80

I just upgraded my Mac to Mac OS X v10.7 (Lion), and now Git is gone:

$ git
-bash: git: command not found

How can I get Git back?

4
  • 1
    Well, where was it? How did you install it originally? Is the directory where it was still in your PATH? Jul 24, 2011 at 22:04
  • 2
    Here exactly the same question apple.stackexchange.com/questions/18470/…
    – jamapag
    Jul 24, 2011 at 22:07
  • 1
    You closed it yet it's exactly on topic based on the link you posted in the closed notice: "software tools commonly used by programmers". Jul 28, 2011 at 19:16
  • I had the same problem but instead of an upgrade, i used the migration assistant to load a new machine based on my old one. xcode was there, but the path to git was no longer found. So I added it to my path as outlined below.
    – dwaz
    Aug 7, 2012 at 4:34

6 Answers 6

149

The default install location is /usr/local, so add this to your ~/.bash_profile file:

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

Then run source ~/.bash_profile in Terminal.

12
  • 1
    I am fairly new to programming and I understand you have to add PATH=/usr/local/git/bin:$PATH to your ~/.bash_profile but I can't seem to find (or access .bash_profile). I tried typing ~/.bash_profile in Terminal but got "Permission denied." I don't otherwise know how to access the .bash_profile (I tried using sudo but it's either not possible or I'm using the wrong sudo commands). I would greatly appreciate help in updating/accessing ~/.bash_profile
    – vich
    Aug 9, 2011 at 17:54
  • Figured it out...since the file was locked I couldn't open it through Terminal so I had to make my hidden files visible then manually open .bash_profile in Finder and add the line of code to make it work. Thanks for the answer!
    – vich
    Aug 9, 2011 at 18:18
  • 3
    on some systems (eg. mine) ~/.bash_profile might be just ~/.profile Sep 12, 2011 at 21:14
  • 1
    i hate to reply to a response of a response, anyways: yes, i can read. yes, i have lion. yes, on my computer the file was ~/.profile; ~/.bash_profile doesn't even exist. Sep 25, 2011 at 17:31
  • 3
    With latest Mountain Lion, you download and install Xcode from the App Store. In Xcode 4.3, git and 11MB of other command line tools are in /Applications/Xcode.app/Contents/Developer/usr/bin. (There's also an option to install Xcode > Preferences > Downloads > Command Line Tools (154.6 MB), I'm not sure what that gives you.
    – skierpage
    Jul 9, 2012 at 0:09
15

If you do not want to install Xcode and/or MacPorts/Fink/Homebrew, you could always use the standalone installer: https://sourceforge.net/projects/git-osx-installer/

2
  • 4
    They didn't have a version for Lion but I used the latest for Snow Leopard and it installed it at /usr/local/git/bin/git. So far so good. :)
    – milesmeow
    Feb 18, 2012 at 16:55
  • That was perfect. Thanks for the tip @milesmeow !
    – MRocklin
    Apr 24, 2012 at 1:18
7

You have to find where the Git executable is and then add the folder to the PATH environment variable in file .bash_profile.

Using terminal:

  1. Search for Git:

     sudo find / -name git
    
  2. Edit the .bash_profile file. Add:

     PATH="<Directory of Git>:$PATH"
    

Git is back :-)

Anyway, I suggest you to install Git using MacPorts. In this way you can easily upgrade your Git instance to the newest release.

4
  • when I entered step one, I got this error "find: git: No such file or directory"
    – JGallardo
    May 6, 2013 at 20:34
  • it seems that you don't have git installed in your system
    – wezzy
    May 11, 2013 at 0:26
  • 1
    @JGallardo The find 'expression' above was broken. It was just using "find / git" but should be "find / -name git". I've edited the answer to be more compatible with all find versions (in case it worked for others already, but I doubt it?)
    – DustinB
    Jul 23, 2013 at 13:13
  • I would had git's directory after the path in order to avoid eventual conflicts Feb 24, 2014 at 8:44
7

There are a couple of points to this answer.

Firstly, you don't need to install Xcode. The Git installer works perfectly well. However, if you want to use Git from within Xcode - it expects to find an installation under /usr/local/bin. If you have your own Git installed elsewhere - I've got a script that fixes this.

Second is to do with the path. My Git path used to be kept under /etc/paths.d/ However, a Mac OS X v10.7 (Lion) install overwrites the contents of this folder and the /etc/paths file as well. That's what happened to me and I got the same error. Recreating the path file fixed the problem.

3
  • 1
    After upgrading to Lion, you can download XCode 4.1 for free from the Mac App Store and it fixes this as well.
    – mattmc3
    Jul 25, 2011 at 17:06
  • Yes, I assumed that was obvious, but good clarification b/c it might not be to some.
    – mattmc3
    Jul 26, 2011 at 0:19
  • 8
    With Xcode 4.3 under Lion, I find git $not$ at /usr/local/bin but rather at /Applications/Xcode.app/Contents/Developer/usr/bin.
    – murray
    Mar 17, 2012 at 20:09
4

It's part of Xcode. You'll need to reinstall the developer tools.

1
  • 2
    Thanks! I naively thought it shipped with the base install.
    – Dmitri
    Sep 10, 2011 at 20:13
1

You can always use MacPorts...

2
  • 1
    You'll need to install the developer tools to use either of these, and Xcode 4.x comes with git already.
    – jarjar
    Jul 24, 2011 at 22:12
  • I tried installing MacPorts but it gave me an error that it could not install to this disk. I am trying to install on a work computer.
    – JGallardo
    May 6, 2013 at 20:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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