Best Setup for Git Branch Completion with Zsh

What’s your favorite zsh git integration?

For some reason, git branch completion broke for me sometime back with updates to git and/or zsh, oh-my-zsh.

I’m using GitHub’s Hub tool which I installed via Homebrew. I then had to manually link to the ZSH completions file from my .zshrc file. It needed to go at the top for some reason, otherwise it wouldn’t work. Using this method I have branch autocompletion working plus some nice Hub features. Just don’t forget to alias “git” to use Hub.

I also use zsh-completions which adds a bunch of other completion functionality. It can be installed into your oh-my-zsh folder if you’re using that, but I prefer to have Homebrew handle it to keep it updated easily. So I used the “manual” installation method where I add it to the fpath just like I did with the Hub completions.

Excerpts from my .zsrhc file are below.

.zshrc

# Add zsh-completions to fpath. See https://github.com/zsh-users/zsh-completions
# This only works if near the top for some reason, maybe it has to do with
# coming before oh-my-zsh.
fpath=(/usr/local/share/zsh-completions $fpath)
fpath=(~/dev/scripts $fpath) # this loads _hub autocompletions

...

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(bundler osx rake ruby rails gem brew)

...