Can't use homebrew installed git

16

3

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.

Matt Stone

Posted 2014-07-03T20:13:16.787

Reputation: 163

Not sure exactly what the problem is, but it sounds like you might want to have a look at the current value of $PATH. – Zev Eisenberg – 2014-07-03T22:36:37.813

3if you wanna see all versions of git you have installed use -> which -a git - (which git, just gives you back the path of the first found one in your PATH variable) to see what paths you have in your PATH do a -> echo $PATH – konqui – 2014-07-05T07:13:58.480

Answers

25

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.

realgeek

Posted 2014-07-03T20:13:16.787

Reputation: 446

hash -r worked for me – metal gear solid – 2017-05-12T09:01:01.867

5

I got the exact same problem. Here is my solution.

brew uninstall git
# make sure everything is alright, maybe brew will give you some hint
brew doctor
brew update  
brew install git
# magic happen, brew will give you hint /usr/bin occurs before /usr/local/bin
# and recommend you run following command
brew doctor
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

After that you are done, however you are not able to see any changes when you run git --version. Just log out and log back in, run git --version again.

Fang

Posted 2014-07-03T20:13:16.787

Reputation: 51

7Opening a new Terminal window is sufficient. Alternatively, one could also call source ~/.bash_profile. – Daniel B – 2014-07-05T07:08:34.327

These steps were exactly what I needed, and they helped me set my system using the latest version of git. I also discovered another copy of git that I had downloaded from git-scm.com, so I ran the uninstall.sh script to remove that one. I am all good now, many thanks to Fang and Jens! – Michael Sheaver – 2016-09-12T22:34:10.257

Thanks for the steps. For me, I was automatically able to use git --version without running the last echo command. – Michael Fulton – 2017-04-14T18:30:54.460

0

I have the same problem. I simply restarted my Terminal.

serial engine

Posted 2014-07-03T20:13:16.787

Reputation: 183

-1

My problem was that I had the Mac GitHub app installed. /usr/local/bin/git was pointing to the app's version of git, not the Homebrew version. Uninstalling the GitHub app fixed the issue for me.

Ben

Posted 2014-07-03T20:13:16.787

Reputation: 541

-1

When using homebrew to update git on your machine, follow the following steps:

brew doctor

Fix the suggested issues

brew update if there is a newer version of homebrew available

brew install git to download and install git's latest version

running brew doctor will let you know that

Warning: You have unlinked kegs in your Cellar

executing brew link git will result in the error

Error: Could not symlink bin/git

Target /usr/local/bin/git already exists. You may want to remove it:

rm '/usr/local/bin/git'

brew link --overwrite git to overwrite the symlink and point to the git brew installed.

Chekkan

Posted 2014-07-03T20:13:16.787

Reputation: 1

-1

Open your terminal. Enter this command.

sudo nano /etc/paths

Then copy the following path in top of file.

/usr/local/git/bin

Press control+ X and save.

Check git --version

Works for me.

Mr Pi

Posted 2014-07-03T20:13:16.787

Reputation: 1

There is no such file git/bin. Do you mean bin/git? Also, there is no need to add this to your paths – /usr/local/bin is already in there. – slhck – 2019-07-08T11:32:46.850