Different versions of Git on Mac OS Yosemite

I am assuming that Git on my macbook was version 1.8.4 because I tried

git --version
git version 1.8.4

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

whereis git
/usr/bin/git

      

later i try to update latest git to 2.0.1, download and install from

http://git-scm.com/download/mac

Since this installer installs Git in /usr/local/git

and adds the path to $PATH

, so now

echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/git/bin

      

I will also replace the binary /usr/bin/

with

sudo cp /usr/local/git/bin/git /usr/bin/

      

And I logged out and logged in but found the following strange situation:

/usr/bin/git --version
git version 2.0.1

git --version
git version 1.8.4

whereis git
/usr/bin/git

      

Where is my mac os looking for when I type git --version

? Where is my previous version 1.8.4 and how can I uninstall it and replace it with my newer version?

+3


source to share


1 answer


The correct way to use another version of git is to put it first in the path. Edit the file adding /usr/local/git/bin

to the path so it adds it instead.

Most likely, there is something like the following in your ~/.bash_profile

or ~/.profile

.

export PATH="$PATH:/usr/local/git/bin"

      

Change it to:



export PATH="/usr/local/git/bin:$PATH"

      


BTW sudo cp /usr/local/git/bin/git /usr/bin/

probably not a good idea as other software might expect the default version to be there. A software update may also replace it.

+4


source







All Articles