In Ubuntu, this comes out of the box but in terminal on OSX a few extra steps are required to get this to work. It is a bit of a hassle figuring out what needs to be done, but once you know, it literally takes 10 seconds.
Step 1: Download auto completion script:
>> cd ~ >> curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
This downloads the auto completion script.
Step 2: Update .bash_profile
>> echo "source ~/git-completion.bash" >> .bash_profile
This adds an extra line into your .bash_profile
That is it! Easy as.
Notes:
- You may need to restart terminal.
- You want to curl the “raw” version of this file: https://github.com/git/git/blob/master/contrib/completion/git-completion.bash so add raw as a subdomain (raw.github.com/etc….) and you’ll see the redirect.
- The -O flag in curl means to download it as a file. Otherwise you’ll see the file echoed out in the terminal.
References:
- https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks
- http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
Thanks a lot, this helped me. For some reason these instructions wouldn’t launch the script https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion but your example worked just fine. Also, works with remote branches which is awesome.
You’re welcome!
Pingback: Homebrew’s `git` not using completion - iZZiSwift