Git supports auto-completion when used via the terminal, which includes all basic commands such as git status
or git checkout
as well as local and remote branch names etc.
It comes pre-installed on Ubuntu, but a few simple steps (bellow) have to be followed to get it working on Mac.
- Open up your terminal app
- Go to your home folder
cd ~
- Download git completion source file from the official git repo
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
. Note: if this link goes dead, just google for the file namegit-completion.bash
and you should be able to find the updated link. - Open your
~/.bash_profile
file (on Mac) or~/.bashrc
file (on other platforms) with your favorite text editor. i.e.vim ~/.bash_profile
- Add the following line at the bottom of the file
source ~/git-completion.bash
and save the file. - Close and re-open your terminal or run
. ~/.bash_profile
to re-load your setting. - You should now have working git autocompletion in your terminal shell.
I initially learned this tip from Git Book, which I highly recommend to any new or intermediate Git users. You may also like my other posts on git – Git Cheatsheet and 19 Tips for Everyday Git Use.
Please let me know in the comment area if you run into any issues.