git autocompletion in OS X Terminal

Jan 26, 2017 · Follow on Twitter and Mastodon gitmacos

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 -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

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon.

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.