ohmyzsh: Git branch completion doesn't work

Hey, I have browsed a number of threads regarding this beyond counting.

I want to be able to hit <TAB> after git checkout and see a list of the local branches that exist in my repository. I was told this would work as-is when I installed zsh and oh-my-zsh from brew. It didn’t, so I tried to debug it in the following ways:

  1. Added git to my plugins. Then I investigated and it only defines a list of aliases
  2. Added gitfast to my plugins. It ships with a git-completion.bash script, but it never sources it anywhere
  3. Tried downloading those scripts: git-completion.bash and git-completion.zsh and sourcing the latter. I also tried each of those steps after removing ~/.zcompdump*.

Perhaps someone with a deeper insight could help. Attachments:

my .zshrc

The tab completion suggests file names for checkout: image

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 5
  • Comments: 16 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I’m going to leave this here on the off chance someone else is converting from bash and doesn’t have all the zsh magic set up in ~/.zshrc

# https://scriptingosx.com/2019/07/moving-to-zsh-part-5-completions/
autoload -Uz compinit && compinit

Everything was all set already; it just needed autoload and compinit then it all just worked after exec zsh.

Disable the gitfast plugin, then run rm $ZSH_COMPDUMP and restart the shell. It should be solved.

Disable the gitfast plugin and make sure you didn’t install Homebrew’s git completion. It shouldn’t matter but try that anyway. You can find git completion files by running:

for d ($fpath); do [[ -e $d/_git ]] && echo $d/_git; done

Homebrew’s provided completion should be in /usr/local/share/zsh/site-functions. Try disabling read permissions to that file, delete zcompdump cache files (rm ~/.zcompdump*), then exec zsh. If that was the issue, git checkout completion should work.

Related: #7062

I’m having the same issue. I had this working on another machine. I’ll check the setup when I can and post back if there isn’t a reply that answers this issue.

Have you tried rm ~/.zcompdump*, then restarting the shell? What does which $_comps[git] show?