26

I have a small problem. At some point I used git but I don't remember if it was installed by default on Lion.

Here is the version and path of git:

$ git --version
git version 1.7.5.4
$ which git
/usr/bin/git

I also have a newer git in /usr/local/git

I would like to use the newer version but I don't know if by removing the old one (/usr/bin has precedence in the path variable) I'll break something.

What is the proper way to resolve this conflict?

5
  • 9
    git is installed by Xcode. I can't tell you if it'll break anything, though. In your shoes, I'd rename it in case I need to put it back later. Commented Feb 3, 2012 at 0:45
  • ah ok..Well what I'll do is just rename the new installt o git2 or something and use it like that.
    – cromestant
    Commented Feb 3, 2012 at 0:52
  • I meant rename the old one, rather than removing it. That way if you DO have problems you can just rename it back. Commented Feb 3, 2012 at 1:10
  • 1
    @StevenFisher you should make that an answer. :)
    – Ian C.
    Commented Feb 3, 2012 at 2:04
  • OK. I was hoping someone would have a real answer that didn't have an "I don't know!" in it. :) Commented Feb 3, 2012 at 2:32

7 Answers 7

26

git is installed by Xcode. I doubt you'll have any problems if you replace it, but I can't give you a definitive answer to that…

  1. What I'd do is rename the old /usr/bin/git to git_old, then rely on your path to select the new one.
  2. If that doesn't work, move the new one to /usr/bin. I doubt Xcode is picky about which version of git it's using.
  3. If that still doesn't work, move git_old back to /usr/bin/git and use either a direct path, rename, or alias for your new one.

I doubt you'll have to go past #1 above, though. That should be enough.

Edit: I read your original post backwards. The first thing you should do is make sure your path includes the new git directory BEFORE the directory that contains the old git.

1
  • 3 alternatives: confirming that the first one worked well. Commented Jul 16, 2012 at 18:28
9

You don't need to go hacking the other version out unless you are really tight for space. Edit your .bash_profile and make sure that /usr/local/bin occurs in front of /usr/bin in your PATH variable

Personally I prefer to adopt a scheme with tool paths defined and the path built from these e.g.

GIT_HOME=/usr/local

PATH=${GIT_HOME}/bin:${PATH};export PATH
MANPATH=${GIT_HOME}/share/man:${MANPATH};export MANPATH

This means that anything that searches for tools using the PATH will find your version of git, and anything that "really must" have the /usr/bin version will most likely have that path hard wired in and can still find it

6

I had the same problem: an old version of Git that was the Xcode version. I've tried to install a new version of Git from http://git-scm.com/ and updated the bash_profile with

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

Then reload your bash and try git --version

Worked for me :)

1

On my system (10.7.3, Xcode 4.3.2) Xcode's git is not installed in /usr/bin/git. All of Xcode 4 (like all apps from the App Store, I think) is in its .app bundle. Specifically, its git is at /Applications/Xcode.app/Contents/Developer/usr/bin/git.

I use git (via Xcode) all the time, and I have no /usr/bin/git here at all. So it's not part of the default Lion install, either, or at least, not at that location.

FWIW, the git in the Xcode.app bundle has a --version that reads:

git version 1.7.7.5 (Apple Git-26)

so I bet your /usr/bin/git is your own installation, and updating it can't hurt anything.

Alternatively, you could install Xcode (it's free!), and put /Applications/Xcode.app/Contents/Developer/usr/bin/ in your $PATH, but that's overkill if you only want git.

2
  • I also have xcode, so I have three versions of git currently installed... nice find!
    – cromestant
    Commented May 15, 2012 at 14:08
  • 1
    if you don't have /usr/bin/git, you probably didn't install the Xcode "Command Line Tools". see stackoverflow.com/q/9329243/152142 Commented Dec 9, 2012 at 16:06
1

Ken is correct in that git was only available through the Xcode.app path. When I installed Mountain Lion (10.8), suddenly I had git in /usr/bin/git, so it was a Mountain Lion addition as far as I can tell...

Although...I have installed quite a few things since and am not entirely sure it wasn't a dependency for something else.

0

I really don't know, I think I haven't installed git or XCode for the momment but after install homebrew and run brew doctor it says:

$ brew doctor
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

    git
    git-cvsserver
    git-receive-pack
    git-shell
    git-upload-archive
    git-upload-pack

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
    echo export PATH="/usr/local/bin:$PATH" >> ~/.bash_profile

So why? I just installed Command Line Tools for XCode (mountain Lion) and I think this one is the one who installed it.

0

I've tried many things. Finally I was able to get brew's version of git to run instead of Xcode's by simply deleting Xcode's additional tools folder:

sudo rm -rf /Library/Developer/CommandLineTools

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .