Cover image for Adding Git Completion to Zsh

Adding Git Completion to Zsh

oliverspryn profile image Oliver Spryn Updated on ・2 min read

I recently switched my shell from Bash to Zsh, and after installing my new favorite extensions (Powerlevel10k and Meslo Nerd Font), I realized I was missing a key component from Bash: Git completion.

Since we don’t all have the luxury of running brew install bash-completion and following the associated directions, I’ll discuss how I manually installed the shell scripts necessary to support Git completion in Zsh.

Finding the Dependencies

The Git community maintains all the shell completion scripts in their repository on GitHub. Navigating to this folder reveals scripts for a variety of shells, including Bash and Zsh.

GitHub Repository

Since both Bash and Zsh are based on the Bourne shell, they tend to share many similarities. Git makes this pretty evident after one opens the git-completion.zsh and the comment at the top states:

You need git’s bash completion script installed somewhere, by default it would be the location bash-completion uses.

Thus, we need two scripts to have Git completion in its entirety.

Downloading the Scripts

Now that it is clear which scripts are necessary for full Git completion functionality, let’s get them:

Notice how, by convention, I placed the shell scripts in a folder called .zsh under the user’s home folder.

Configuring the Shell

Once the scripts are in position, the .zshrc file may be configured to provide access to their functionality. Open up the ~/.zshrc file and add the following lines of code:

On your first run, make sure you clear out the shell’s autocompletion cache with:

Then save the script, reload your shell, and voila!

Final Result

For the curious reader, here’s a quick summary of what the above configuration script accomplishes:

  • zstyle: Instructs the shell on how to provide inline, contextual hints
  • fpath: The git-completion.zsh is a function file, not designed to be sourced like the bash script. This command appends the ~/.zsh directory onto the shell’s function lookup list.
  • autoload: Scan each path within the fpath variable for files starting with an underscore (_git, in our case) and loads the corresponding script as a function file
  • compinit: Initializes the shell’s auto-completion functionality


These links proved themselves immensely helpful as I learned how to understand and configure this on my own:


Editor guide

Zsh ships with Git completions. All you need to do is initialize the completion system by placing autoload -Uz compinit && compinit into ~/.zshrc.


Hello Roman. It's nice to talk to the creator of my favorite shell extension. :) Thank you for taking the time to comment.

I realized that after wrote this article. In my experience, which is primarily with Windows Terminal and WSL Ubuntu, I noticed that the scripts provided by Git run several orders of magnitude faster than the built-in zsh option. I often wait between 3 and 15 seconds for tab completion to work using strictly zsh, and get tab completion results immediately if I follow the steps in this article for Git's option.

Perhaps it is just my setup, or an issue with WSL, but I prefer to stay with Git's option. Nevertheless, thanks for sharing.