user3545063
user3545063

Reputation: 811

git --version command returns different result from what's actually installed

Tried to update my git with homebrew and I encountered this problem:

MBP:GitHub_Tutorial nasdas$ brew install git
Warning: git 2.21.0 is already installed and up-to-date
To reinstall 2.21.0, run `brew reinstall git`
MBP:GitHub_Tutorial nasdas$ git --version
git version 2.17.2 (Apple Git-113)

Upvotes: 4

Views: 1719

Answers (1)

torek
torek

Reputation: 488629

Presumably you have both versions installed, independent of each other.

Use type git or which git to see which one you're running. It's probably /usr/bin/git. The brew-installed one is probably /usr/local/bin/git. Change your $PATH (or $path or whatever your shell uses) to put /usr/local/bin before /usr/bin so that git will run the new one instead of the old one, or use /usr/local/bin/git to run the new one.

(And, as Greg Bacon notes in a comment, note that you might have to run hash -r in various shells to get them to check again after installing something in /usr/local/bin, if they've already decided that git means /usr/bin/git even though $PATH has /usr/local/bin earlier. In csh/tcsh this is rehash instead of hash -r.)

(It turns out to have been the hash issue—your shell decided, earlier, that git meant the old one. Logging in again also clears this sort of thing up, but that's a pain!)

Upvotes: 8

Related Questions