I installed git via apt-get, but found that the version was hopelessly outdated, so I then installed git from source. The end result is rather puzzling:

$ git --version
git version 1.7.0.4
$ which git
/usr/local/bin/git
$ /usr/local/bin/git --version
git version 1.7.6

It appears that which is lying to me...which seems unlikely. What is actually going on here, and how can I get a bare call to git to run the correct version?

link|improve this question
4  
what shows whereis git? and less probable, what shows type git? – hmontoliu Aug 5 '11 at 18:24
Why not simply uninstall the version you got from apt-get if you don't want it? – Zoredache Aug 5 '11 at 18:24
Did you remove the binary version from apt-get? – quanta Aug 5 '11 at 18:25
@hmontoliu useful commands! I didn't know about either of those. whereis git: git: /usr/bin/git /usr/local/bin/git /usr/share/man/man1/git.1.gz. type git: git is hashed (/usr/bin/git). What does "git is hashed" mean? – Josh Bleecher Snyder Aug 5 '11 at 18:30
@ Zoredache, quanta: Yep, that seems like a sensible thing to do. I just like to understand what's going on, in addition to fixing the problem. – Josh Bleecher Snyder Aug 5 '11 at 18:32
feedback

2 Answers

up vote 10 down vote accepted

which is telling the truth. Your shell is lying to you.

git is hashed (/usr/bin/git)

means that your shell has cached this location of "git" and is using the cached path rather than searching $PATH again. Use hash -r to clear the cache and make the shell search $PATH for the new git at /usr/local/bin/git

link|improve this answer
That was it! Thanks, for both the solution and the clear explanation. – Josh Bleecher Snyder Aug 5 '11 at 19:07
feedback

Did you set up an alias for git in your shell?

$ alias git="/bin/echo This is not the git you are looking for"
$ which git
/usr/bin/git
$ git --version
This is not the git you are looking for --version
$ /usr/bin/git --version
git version 1.7.4.1
$ type git
git is aliased to `/bin/echo This is not the git you are looking for'
$ unalias git
$ type git
git is /usr/bin/git
$ git --version
git version 1.7.4.1
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.