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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
  • 1
    Well, where was it? How did you install it originally? Is the directory where it was still in your `PATH`? – Greg Hewgill Jul 24 '11 at 22:04
  • 2
    Here exactly the same question http://apple.stackexchange.com/questions/18470/git-not-found-after-installing-os-x-lion – jamapag Jul 24 '11 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". – Oscar Godson Jul 28 '11 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 07 '12 at 04:34

6 Answers6

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris Ledet
  • 11,458
  • 7
  • 39
  • 47
  • 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 09 '11 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 09 '11 at 18:18
  • Git does not ship with the base OS X Lion install, you need to install X Code, not all of it if you don't want it, of course. See the helpful note below. – Dmitri Sep 10 '11 at 20:12
  • 3
    on some systems (eg. mine) `~/.bash_profile` might be just `~/.profile` – kritzikratzi Sep 12 '11 at 21:14
  • @kritzikratzi he's talking about Lion not other systems. – Chris Ledet Sep 13 '11 at 01:55
  • 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. – kritzikratzi Sep 25 '11 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 09 '12 at 00:09
  • @kritzikratzi, read `man bash`: "looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists..." Only use ~/.profile if you use other bash-compatible shells and want the same settings in all. – skierpage Jul 09 '12 at 00:16
  • @skierpage yea, i guess that's the behavior you want with path variables :) btw., i'm using zsh, that would also explain the lack of a .bash_profile – kritzikratzi Jul 09 '12 at 18:43
  • This worked to fix my mountain lion install, I love you. Thank you so much. – Leonardo Dario Perna Jul 26 '12 at 22:46
  • make sure you have downloaded the Xcode Command Line Tools before trying the above (at least for Mountain Lion). – brainray Jul 28 '12 at 07:35
  • I'm giving you an upvote anyway but just to be clear the path on Mountain Lion is /Applications/Xcode.app/Contents/Developer/usr/bin as mentioned by @skierpage – Cfreak Jul 31 '12 at 19:55
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/

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zakx
  • 681
  • 5
  • 17
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
wezzy
  • 5,897
  • 3
  • 31
  • 42
  • when I entered step one, I got this error "find: git: No such file or directory" – JGallardo May 06 '13 at 20:34
  • it seems that you don't have git installed in your system – wezzy May 11 '13 at 00: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 '13 at 13:13
  • I would had `git's directory` after the path in order to avoid eventual conflicts – Thomas Ayoub Feb 24 '14 at 08: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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abizern
  • 146,289
  • 39
  • 203
  • 257
  • 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 '11 at 17:06
  • Yes, I assumed that was obvious, but good clarification b/c it might not be to some. – mattmc3 Jul 26 '11 at 00: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 '12 at 20:09
4

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jarjar
  • 1,681
  • 2
  • 15
  • 19
1

You can always use MacPorts...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Manlio
  • 10,768
  • 9
  • 50
  • 79
  • 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 '11 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 06 '13 at 20:35