When in a repository directory, use tab(Tab key on keyboard) to automatically complete Git commands and branches like normal bash commands.

How to get this working:



First you need to get  git-completion.bash  script (see it here) and put it in your home directory:

curl -L https://raw.github.com/uditiiita/Git-Scripts/master/git-completion.bash -o ~/.git-completion.bash


Open the Terminal and if the file ~/.bash_profile does not already exists, then create it with the following command:

touch ~/.bash_profile

Next, add the following lines to your .bash_profile. This tells the bash to execute the git branch script if it exists.

1
2
3
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi

Note: You can use the file ~/.bashrc instead to make this method applicable to Linux.
Now when you change to a directory that is within a GIT repository, then you can use tab key to auto-complete the commands and branch names.

If you are using an existing Terminal session, don’t forget to make the changes take effect by sourcing the file with the command:
source ~/.bash_profile