git autocompletion in OSX Terminal

26 Jan 2017

After procrastinating for too long, I finally decided to spend one minute of my life to setup git autocomplete on my work computer.

The original discussion thread from where I got this information can be found at this page.

First, run the following command in the Terminal, to get the autocomplete script:

curl -o ~/.git-completion.bash

This will download the autocomplete script and place it as a hidden file in your home folder.

Then, open (or create if you have none) ~/.bash_profile and add the following:

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

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

After this, you can press tab while typing a branch name, to get the Terminal to auto complete the branch name as much as possible, just as when you type cd.