15 Jun 2012

How to add auto-completion to git

Sometimes git projects can have a lot of different branches, and you might need to frequently check out different branches. It can be tedious to write out the entire branch name every time (especially if you tend to have longer branch names). Luckily, there's a fix for that: git auto-complete.

You'll need to make the file git-completion.bash permanently available to your .bash_profile file. The easiest way to do that is to copy the file into your home directory as .git-completion. Here are the three easiest methods to copy that file into place - choose the one method that you're most comfortable with...

A) With cURL:

curl https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion

B) With wget:

Install wget, if you don't already have it:

brew install wget

Use this command to create the .git-completion file:

wget https://raw.github.com/git/git/master/contrib/completion/git-completion.bash -O ~/.git-completion

C) Manually:

Go to the URL https://raw.github.com/git/git/master/contrib/completion/git-completion.bash, and save the file as .git-completion in your home directory.

With that file in place, you'll need to edit your ~/.bash_profile file with your editor of choice. Just add this line to the end of the file:

source ~/.git-completion

After saving the .bash_profile changes, you will need to quit Terminal then re-open it for the changes to take place. Alternatively, you can run this command to force the changes without restarting Terminal:

source ~/.profile

Now branch names are auto-completed in Terminal! If you have a branch named "some-other-new-feature" (and let's assume for this example that you have no other branches that start with the letter s) then you can check out the branch with git chec<tab> s<tab>, which will auto-complete both of the <tab> keystrokes out to git checkout some-other-new-feature.


bash cURL git homebrew mac terminal wget

Related Posts

17 Dec 2013 Donoku
28 Dec 2012 How to make SublimeLinter work with Ruby & RVM
09 Dec 2012 The tech behind getting Blizzalert into its third season
03 Nov 2012 Little-Corner is now a Heroku-ready Rails app
14 Oct 2012 Sip as a replacement for Pick as a replacement for Digital Color Meter in Mac OS X