Macos – Can’t use homebrew installed git

githomebrewmacososx-maverickspath

I'm encountering a really weird issue when I try to use the latest version of git I just installed via homebrew. which git is pointing me to the homebrew install, but calling git returns the original version installed with OS X.

I checked first to see the original version I was on.

[user@home ~]$ git --version
git version 1.8.5.2 (Apple Git-48)

Then I went to homebrew to install the latest version.

[user@home ~]$ brew install git
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-2.0.0.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring git-2.0.0.mavericks.bottle.2.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
  /usr/local/bin/git-credential-osxkeychain

The 'contrib' directory has been installed to:
  /usr/local/share/git-core/contrib

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
?  /usr/local/Cellar/git/2.0.0: 1324 files, 31M

Looks like it worked! Check that it's pointing to the correct git

[user@home ~]$ which git
/usr/local/bin/git

Should be good, right? Not so fast

[user@home ~]$ git --version
git version 1.8.5.2 (Apple Git-48)

That's weird. Am I really pointing to the right git?

[user@home ~]$ ls -l /usr/local/bin/git
lrwxr-xr-x  1 user  group  27 Jul  3 15:54 /usr/local/bin/git -> ../Cellar/git/2.0.0/bin/git

Sure looks like it. Works when I call it manually

[user@home ~]$ /usr/local/Cellar/git/2.0.0/bin/git --version
git version 2.0.0

But not as git

[user@home ~]$ which git
/usr/local/bin/git
[user@home ~]$ git --version
git version 1.8.5.2 (Apple Git-48)

Any ideas as to what could be causing this?

EDIT: Solved it. source .bashrc fixed it. Still curious as to why which would return me the correct executable but it wouldn't be called though, if anyone can explain that.

Best Answer

Shells maintain a cache of the paths where executables were found in the $PATH variable. So it cached /usr/bin/git rather than /usr/local/bin/git, because the latter didn't exist when your shell started. Running hash -r in Bash from your current terminal will clear this cache, then the first instance found in $PATH should be the one that executes.

Related Question