How to Enable Git Tab Autocomplete on Your Mac

  Matt Cone       January 21, 2021      Tutorials Mac Developer


The git version control system is a popular choice among developers when working with source code. Git is automatically installed on every Mac by default, but you might want to enable the git tab autocomplete feature to help you automatically complete commands and branch names.

This feature is a must-have if you work with long branch names. For example, if you typed git checkout ma and then pressed the Tab key, git tab autocomplete would automatically fill in the rest of the branch name, like this: git checkout main.

Follow the instructions in this tutorial to enable git tab autocomplete on your Mac.

Enable Git Tab Autocomplete for Zsh

New Macs use the Zsh shell by default. If you’re using Zsh, add the following line to the ~/.zshrc file and restart your Terminal application:

autoload -Uz compinit && compinit

Alternatively, you can run the following two commands in your Terminal application to add the necessary line to the .zshrc file and restart your shell.

echo 'autoload -Uz compinit && compinit' >> ~/.zshrc
source ~/.zshrc

Git tab autocomplete is now enabled on your Mac.

Enable Git Tab Autocomplete for Bash

If your Mac is set to use the Bash shell, follow these instructions to enable git tab autocomplete on your Mac:

  1. Download the necessary script to your Mac by using the following curl command:

    curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
    
  2. Add the following line to the ~/.bash_profile file:

    if [ -f ~/.git-completion.bash ]; then
      . ~/.git-completion.bash
    fi
    
  3. Make the Bash script executable by running the following command:

    chmod +x ~/.git-completion.bash
    
  4. Restart your Terminal application or run the following command:

    source ~/.bash_profile
    

Git tab autocomplete is now enabled on your Mac.

Subscribe to our email newsletter

Sign up and get Macinstruct's tutorials delivered to your inbox. No spam, promise!


About    Privacy Policy    Terms and Conditions

© 2023. A Matt Cone project. CC BY-NC-SA 4.0. Made with 🌶️ in New Mexico.