I have stumbled upon the very same error on a Mac OS. The cause is a conflict between the version of Git included in Xcode Command Line Tools and the Git LFS version installed via HomeBrew.
Basically, as hinted by the top voted answer, the Git binary executable (git
) expects the binary executable of the Git LFS extension to be located inside the directory of its execution path.
Even though the Git binary executable installed by Xcode Command Line Tools is physically located in /usr/bin/git
~ which git
/usr/bin/git
its execution path is another directory
~ git --exec-path
/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core
Therefore git
is not able to find git-lfs
binary inside /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core
, as the latter is located in /opt/opt/homebrew/bin/git-lfs
~ which git-lfs
/opt/homebrew/bin/git-lfs
That explains the need of the symlink proposed in the top answer:
sudo ln -s "$(which git-lfs)" "$(git --exec-path)/git-lfs"
Unfortunately, in recent versions of Mac OS that command does not work:
~ sudo ln -s "$(which git-lfs)" "$(git --exec-path)/git-lfs"
ln: /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git-lfs: Operation not permitted
That error is due to the System Integrity Protection, aka "SIP", a feature enabled in recent versions of Mac OS. It basically makes parts of the file system read-only to everybody, including root: even prepending sudo
, as shown above, is ineffective.
Said that, the only solution that worked for me was installing also Git via brew
~ brew install git
ensuring that the HomeBrew binaries have precedence over system ones:
~ echo $PATH
opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/Library/Apple/usr/bin