How to enable auto complete for git commands and branches on Mac OSX terminal / Command line

GIT and Bash Logos

If you want to enable tab auto complete at the command line on Mac OSX terminal, there is a handy auto-completion script you can use.

Using git-completion script to enable auto complete for GIT commands

    1. Download and save the git-completion script to your home directory
      curl -o ~/.git-completion.bash
    2. Then open the .bash_profile file in your home directory
      vi ~/.bash_profile
    3. Add this at the end of .bash_profile
      if [ -f ~/.git-completion.bash ]; then
        . ~/.git-completion.bash
    4. Make the .git-completion.bash in your home directory executable
      chmod +x ~/.git-completion.bash
    5. Finally reload the .bash_profile with the following command, or just close and re open the shell and your git auto completion should be working.
      source ~/.bash_profile

The same method can be adapted to Centos6, Centos 7, Ubuntu, RHEL or any other bistro.

Feel free to leave a comment if you face any issues.

Leave a Reply

Your email address will not be published. Required fields are marked *