Git auto-completion on Mac

A few months back when I reinstalled my mac I was surprised that my tab completion stopped working and it didn’t finish the git commands and branch names. It turns out that you have to install it by hand. To do so, you’ll need git (errr, obviously) and a package called bash-completion.

brew install git && brew install bash-completion

Now add the following lines into your .bash_profile to initialise the bash-completion and reload it.

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi

And you are done and can use tab to complete any command or git object. Combine it with the git status display in terminal and you have another powerful tool configured under your belt.

Resources


Would you like to get the most interesting content about programming every Monday?
Sign up to Programming Digest and stay up to date!