ohmyzsh: compinit: _git not found on OS X 10.11

I want to fix the issue that shows

compdef: unknown command or service: git

I run rm -f ~/.zcompdump*; compinit, then it shown that

compinit:496: no such file or directory: /usr/local/share/zsh/site-functions/_git

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 24 (10 by maintainers)

Most upvoted comments

@apjanke

One more thing to check: that /usr/local site-functions dir does exist. What happens if you remove it (by renaming it to site-functions-OFF or similar) and then rm ~/.zcompdump* and then launch a new zsh session?

this help me, thanks!

Just add ‘gitfast’ plugin to your .zshrc

your plugins directive should be like following plugins=(git gitfast)

I put together a test box running the OS X 10.11 public beta, updated as of today (7/21/2015). I’m unable to reproduce this on 10.11 in the default setup. My test box is a fresh install of OS X 10.9 which was then upgraded to 10.11.

When you say the file is empty, you mean that it is present but is 0 bytes long? Is the file a symlink, and if so, what is it pointing to?

The /usr/local/share directory doesn’t exist by default on OS X 10.11. It seems likely that that _git file on your system was leftover from an installation of a previous piece of software. The current Homebrew git formula provides that file, so it’s a likely candidate.

I was able to reproduce this error by installing the Homebrew git on 10.11 with brew install git and then breaking it by doing cd /usr/local/Cellar/git/2.4.6/share/zsh/site-functions; mv _git _git-OFF. After rm ~/.zcompdump*, I get this error upon starting a new zsh session.

compinit:496: no such file or directory: /usr/local/share/zsh/site-functions/_git

This breakage would not have happened on 10.10 or prior versions of OS X because /usr/local/share/zsh/site-functions is not in $fpath by default in the system zsh in earlier versions of OS X. (This change is probably related to the new “rootless” System Integrity Feature which locks down /usr/share.)

It seems likely that this file was just left over from a broken previous installation of Homebrew git or another program that supplied it, and upgrading to 10.11 exposed the error due to the change in $fpath.

If that’s the case, you could fix it by doing either of:

  • Repair the installation of the program that supplied that /usr/local/share/zsh/site-functions/_git file
  • Delete the broken /usr/local/share/zsh/site-functions/_git file

Loading the gitfast plugin will take care of it because gitfast contains a _git file, too, which will be ahead of the broken one on the path. But this will only work if you are running Oh My Zsh and using that plugin. Other zsh sessions which run compinit would still be affected.

@noisebai I add the ‘gitfast’ plugin on my .zshrc file, and source ~/.zshrc , solve it !