git autocompletion in OS X Terminal

After procrastinating for too long, I finally spent a minute to enable 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 https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -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:

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.

Discussions & More

If you want to discuss this post, please share your thoughts on Bluesky and Mastodon. Make sure to follow to be notified when new content is published.