git autocompletion in OS X Terminal

Jan 26, 2017 gitmacos

After procrastinating for too long, I finally spent a minute to setup git autocomplete in the Terminal. The original discussion on this topic is found here.

To enable git autocomplete, first run the following command to download the autocomplete script:

curl -o ~/.git-completion.bash

This will download the script and place it as a hidden file in your home folder. After this, open or create ~/.bash_profile and add the following to it:

test -f ~/.git-completion.bash && . $_

This will make the Terminal run the .git-completion.bash script if it exists.

After this, restart the Terminal or open a new tab to apply this change. You should now be able to use autocomplete for branch names, git commands etc.