Case in point:
I\'m a on mac with bash v3.2.17, I\'m using git installed via macports with the bash_completion variant.
When I type git checkout m<
One more option is to use ~/.bash_completion file. To create the gco alias for git checkout just put this in there:
_xfunc git __git_complete gco _git_checkout
Then in ~/.bashrc you have to put just the alias itself:
alias gco='git checkout'
Two lines. That's it.
Explanation:
The ~/bash_completion gets sourced at the end of the main bash_completion script. In gentoo I found the main script in /usr/share/bash-completion/bash_completion.
The _xfunc git bit takes care of sourcing the git-completion file for you so you don't need to put anything else in ~/.bashrc.
The accepted answer require you to copy .git-completion.sh and source it from your ~/.bashrc file which I find lame.
PS: I'm still trying to figure out how not to source the whole git-completion script into my bash environment. Please comment or edit if you find a way.