clubmate.fi

A good[ish] website

Web development blog, loads of UI and JavaScript topics

Tab complete Git commands and branches

Filed under: System— Tagged with: git, shell

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

👉 See also: my post on fish shell, fish has awesome autocomplete built in.

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

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

Then add the following to your .bash_profile:

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

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

To view all your branches in a give repo, for example, start with branch and hit tab:

$ 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 the example repo has a lot a badly named feature branches.

Comments would go here, but the commenting system isn’t ready yet, sorry.

  • © 2022 Antti Hiljá
  • About
  • All rights reserved yadda yadda.
  • I can put just about anything here, no one reads the footer anyways.
  • I love u!