Git bash completion = Yay!

If you've heard of, or are already using bash completion, you'll know how great it is. Here's how to use it with Git.

How to get the sweetness?

I'm using Ubuntu (Hardy), but setup instructions should be similar for others. For Ubuntu, uncomment this section in /etc/bash.bashrc and you've enabled bash completion. You'll need to open a new terminal for it to take affect.

1
2
3
if [ -f /etc/bash_completion ]; then
 . /etc/bash_completion
fi

How to enable Git completion

You'll need the bash completion file for Git. This file details how the Git commands will be completed. The file comes as part of the Git distribution.

  • Download the lastest git release from http://www.kernel.org/pub/software/scm/git/
  • Find the git-completion.bash file in the contrib/ directory and copy to the /etc/bash_completion.d/ directory
  • Start a new login shell (logout/login or start a new Terminal tab)

Try it out

Now, typing git <tab><tab> should list all of the various git commands (of which there are many). However, the really cool part is that it will also list your branches for you. Typing git checkout <tab><tab> within your Git repo will list all of the branches you have.

1
2
jord@jordan /home/jord/webby(master) $ git checkout <tab><tab>
HEAD    master

RSI, be gone!

Thanks