Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
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. –  Steven Fisher Feb 3 '12 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 Feb 3 '12 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. –  Steven Fisher Feb 3 '12 at 1:10
1  
@StevenFisher you should make that an answer. :) –  Ian C. Feb 3 '12 at 2:04
    
OK. I was hoping someone would have a real answer that didn't have an "I don't know!" in it. :) –  Steven Fisher Feb 3 '12 at 2:32

6 Answers 6

up vote 18 down vote accepted

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.

share|improve this answer
    
3 alternatives: confirming that the first one worked well. –  Marius Butuc Jul 16 '12 at 18:28

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

share|improve this answer

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 :)

share|improve this answer

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.

share|improve this answer
    
I also have xcode, so I have three versions of git currently installed... nice find! –  cromestant May 15 '12 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 –  Justin M. Keyes Dec 9 '12 at 16:06

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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