Git autocomplete in Mac OS X

I always liked that my Git installations on Unix and Linux comes with the contrib/complete/git-completion.bash script activated or easily activated. But its harder if you use the pre-built binaries for Mac OS X.

To get autocompletion to work on Mac OS X when installing the pre-built binaries do this.
UPDATE: Instead of step 1 and 2 below you can get the completion script directly from Github. Thanks to Fredric.

curl http://github.com/git/git/raw/master/contrib/completion/git-completion.bash -O

UPDATE: 2011-01-03 All github.com url are now https. Thanks to Julio.

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

UPDATE: 2011-07-15 Added -L option to allow for curl to handle redirects.Thanks to michaelyoung.

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

1. Download the Git source from git-scm.com.
2. Unpack and copy the completion script git-completion.bash found in contrib/completion to your home directory.

3. Add the following to your ~/.profile or ~/.bash_profile

source ~/git-completion.bash
 
alias gco='git co'
alias gci='git ci'
alias grb='git rb'

4. Add the following to your ~/.gitconfig

[alias]
co = checkout
ci = commit
rb = rebase

Restart Terminal and start Tabbin’!

More Git tips that I found usefull can be found on Tim Dysinger’s blog http://dysinger.net/2007/12/30/installing-git-on-mac-os-x-105-leopard

34 Responses to “Git autocomplete in Mac OS X”

Leave a Reply