Git Aliases
Once you start developing some experience with using git on the command line, you will sometimes find yourself typing some long commands over and over again. You can create aliases in git that are very similar to the bash alias shortcuts you use in the shell.
Steps to do this are highlighted in chapter 2.7 of the Git Book authored by Scott Chacon and Ben Straub and published by Apress.
One of the commands that I use a lot is:
Setting Up Git to Ignore ELF Binaries (C/C++ Output on Linux)
The starting point for this experiment was from here
An Example using C Program Source
Let’s say we have a pre-existing directory of some C source code files:
$ lsMakefile print print.c print.h print.o
And we initialize a new git repository in that directory:
$ git initInitialized empty Git repository in /home/user/tmp/printer/.git/$ cat .gitignore# Ignore all*# Unignore all with extensions!*.*# Unignore all dirs!*/# Unignore make files!Makefile# Ignore .o files*.o# Ignorebindirbin/# or*/bin/*
Processing a List of Files from an Input File
Suppose we have a list of files stored in a text file and we want to perform an operation on each of them within a bash script. How would we go about doing that? Well, there are several options, here are a few.
$ cat input-files.txtfile-1.txtfile-2.txtfile-3.txtfile-4.txtfile-5.txtfile-6.txtfile-7.txtfile-8.txtfile-9.txt
String Processing with Bash
There are various tools built into bash that enable you to manipulate a variable or string which come in handy when writing shell scripts. Here are a few notable ones:
Find the length of a string
${#string}
Get a Substring from a String
${string:pos} or ${string:pos:len}
Removing Substrings from a String
${string#substr}${string%substr}${string##substr}${string%%substr}
Convert a Git Repo to a Bare Repo
If you have a git repository that you haven’t cloned from a remote location, i.e., one that was created locally, it is easy to convert it to a bare repository. This process describes how to:
- Take a “normal” git repository
- Move the .git directory to another location
- Convert it to a bare repository
Suppose you have a git repository called repo. To convert it to a bare repository, execute the following commands:
Git: Working with Git for the First Time
Here’s the first step every user should start with after downloading and installing git but BEFORE doing anything else: Set up your global environment variables! If you don’t do this git will abort your commit and give you an annoying message like this one:
$ git commit file.txtAuthor identity unknown*** Please tell me who you are.Rungit config --global user.email "you@example.com"git config --global user.name "Your Name"to set your account's default identity.Omit --global to set the identity only in this repository.fatal: empty ident name (for <user@localhost>) not allowed
Git: Committing to a Different Branch
Let’s imaging that you’ve made some changes to files in your work directory and then realized that you aren’t in the correct branch. Now you want to get the changes you’ve made to the right branch but no change the current branch. What do you do?
There is no git command to do this but you can use the git stash command to fix this.
This involves:
- Using the git stash command to temporarily store our changes elsewhere,
- Checkout the correct branch, and
- “Unstash” the changes to the correct branch.
Let’s say that we’ve made some changes in our repository’s new-release branch but they should have been made in the new-feature branch.
Printing from Virtualbox
If you want to set up your system so that you can access your Linux host’s printer from a Windows VirtualBox client then:
On Your Linux Host
- Install your printer driver. Get your printer working on your host first.
- Install CUPS if it is not already installed.
- Add your printer to CUPS at
http://localhost:631/admin. - Set your virtual machine’s Network to Bridged Adapter (eth0) in Settings and connect the cable as necessary (Advanced menu).
- Startup VirtualBox.
- In a terminal, enter
ifconfigto list your current network settings and copy down your host’s (eth0) address or you can optionally access this address using Network Manager.
On You Windows Client
Installing and Using sbotools in Slackware 15.0
Slackware was the first Linux distribution that I ever used but I was always curious and did a lot of distro-hopping from Slackware, Caldera, Turbo Linux, Mandrake, Red Hat, Ubuntu, multiple Ubuntu derivatives, then Fedora for quite a while until I finally settled on…(drum roll please)…Slackware! Yeah, I’ve come full circle.
One of the reasons why I was doing so much hopping around is that I was never really happy with something about the distribution that I was currently using. Maybe it was the default colors (Ubuntu, come on with all of that orange stuff), choice of default software, difficulty with setting it up. Whatever. With Slackware it was always the (lack of) a decent package management system. That is until I found “sbotools”.
Sorting Stuff in the VIM Buffer
Suppose I have a file that I am editing in vim with the following contents:
$ cat file.txtRed 4Blue 3Green 1Orange 7Black 8Yellow 6Purple 2White 5