Tab complete Git commands and branches

Here's a quick post on the awesomeness of tab completion, and how it can be applied to Git commands and branch names.

There’s a little helper app called git-completion.bash. Crab it to your home dir:

$ curl -o ~/.git-completion.bash

Then add the following to your .bash_profile:

if [ -f ~/.git-completion.bash ]; then
    . ~/.git-completion.bash

If you now type git<tab>, a hoard of commands will pop up:

$ git <tab>
add                  clean                gc                   p4                   selfupdate
alias                clone                get-tar-commit-id    pull                 send-email
am                   column               grep                 pull-request         shortlog
annotate             commit               help                 push                 show
apply                compare              imap-send            rebase               show-branch
archive              config               init                 reflog               stage
bisect               create               instaweb             release              stash
blame                describe             interpret-trailers   relink               status
branch               diff                 issue                remote               submodule
bundle               difftool             log                  repack               subtree
checkout             fetch                merge                replace              svn
cherry               filter-branch        mergetool            request-pull         tag
cherry-pick          fork                 mv                   reset                verify-commit
ci-status            format-patch         name-rev             revert               version
citool               fsck                 notes                rm                   whatchanged

For branch information just start with branch:

$ git branch <tab>
FETCH_HEAD                       new-security-page                origin/add-language-to-support
HEAD                             new-security-page-bu             origin/master
ORIG_HEAD                        new-stuff                        origin/new-js
linted-js                        old-master                       origin/new-stuff
master                           old-stuff
new-js                           origin/HEAD

As you see this repo has a lot a, badly named, feature branches :)

Club-Mate, the beverage →