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:
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
Add the following line to the
~/.bash_profile
file:if [ -f ~/.git-completion.bash ]; then . ~/.git-completion.bash fi
Make the Bash script executable by running the following command:
chmod +x ~/.git-completion.bash
Restart your Terminal application or run the following command:
source ~/.bash_profile
Git tab autocomplete is now enabled on your Mac.
Related Articles
- How to Set Nano as the Default Editor for Git on Your Mac
- How to Tell What Shell Your Mac is Using
- How to Set Bash as the Default Shell on Mac
- How to Make a Bash Script Executable on a Mac
Subscribe to our email newsletter
Sign up and get Macinstruct's tutorials delivered to your inbox. No spam, promise!