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 just upgraded to OS X Lion and now cannot initialize Git where it used to work fine:

$ git add .

-bash: git: command not found

I'm new to Git and to programming, so I'm sure it's a quick fix, any help is greatly appreciated. Thanks guys!

share|improve this question

migrated from stackoverflow.com Jul 24 '11 at 10:11

This question came from our site for professional and enthusiast programmers.

1  
do you have macports installed? –  jamapag Jul 20 '11 at 16:57
    
i do not...do you recommend installing? –  pruett Jul 20 '11 at 16:58
9  
personally I would install it using homebrew instead of macports - mxcl.github.com/homebrew –  house9 Jul 20 '11 at 17:56
2  
brew > ports, also maybe git just isn't in your $PATH any longer. Try sudo find / -name git and you might just find your binary. –  Nick Radford Jul 20 '11 at 18:05
1  
Why would you recommend Macports or Homebrew just for git? Just curious. I've been using code.google.com/p/git-osx-installer –  Yar Apr 24 '12 at 22:45

16 Answers 16

Possibly, you had installed git through MacPorts or Fink.

I think it will take some time to have a release of either for Lion... or possibly you should try and reinstall it...

Indeed, it seems that you need to install MacPorts from trunk to get Lion compatibility...

Fink has also got some hints about upgrading to Lion.

share|improve this answer
    
I had macports installed and working before my Lion upgrade. My port command still works fine (ex: port selfupdate) but now my installed ports (ex: git) do not. I can see the packages are still in /opt/local/var. I thought it may be a $PATH issue, but ~/.profile still has my previous (before upgrade) macports configurations. Any suggestions? –  Adam Tootle Jul 20 '11 at 19:57
    
@Adam Tootle: See the "install MacPorts from trunk" bit in my answer... –  sergio Jul 20 '11 at 20:03
    
I wasn't sure if I needed that or not since it was working ;) If I do that I shouldn't have to reinstall all of my packages should I? –  Adam Tootle Jul 20 '11 at 20:06
    
@Adam Tootle: I do think so... the point is that with Lion all system frameworks and libraries have changed (as usual with a major release)... –  sergio Jul 20 '11 at 20:16
    
ahh..gotcha. well there goes any productivity for the afternoon haha –  Adam Tootle Jul 20 '11 at 20:21
up vote 55 down vote accepted

Lion (and Snow Leopard) didn't ship with git - so perhaps the way you installed git didn't survive the upgrade. You'll need to find your copy of git or just get a new copy. Using spotlight to search your Time Machine backups might be fruitful to find the files and know if it's a path issue or the binaries are truly gone after Lion migrated your data.

All of your repos stored in user space are fine. Do try to get the same or newer version of git.

The command line mdfind -name git will list all files that spotlight has seen with git in the name. Most installations of git should survive an upgrade to Lion and you only have to clean up your environment or link to the binary from somewhere in your $PATH.

Xcode 4(4.0-4.2) drops git into /Developer/usr/bin along with most of the other tools you need like make and gcc. It might be simplest to maintain git after getting the (currently) free Xcode from the App Store. Xcode 4.3 puts giy and other tools in Applications/Xcode.app/Contents/Developer/usr/bin.

To avoid issues with different versions, you might want to make sure any old versions are gone from your hard drive. (and certainly from your $PATH)

share|improve this answer
    
AWESOME! I posted this question while downloading the new Xcode. Just checked now and it works! Thanks @Johan Nordberg –  pruett Jul 21 '11 at 14:26
3  
Note XCode for Lion just installs the installer. You'll need to visits your apps folder and run a install app to have git. –  nailer Jul 21 '11 at 16:27
2  
I have Git in /usr/bin/git. I installed Xcode 4 on a clean (reformat) install of Lion and I don’t remember ever running the Git installer. –  Nate Aug 1 '11 at 16:57
1  
I have Lion (10.7.3) and just installed XCode via the App store. It's in the Applications directory and not Developer. In fact I don't even have a /Developer directory. –  milesmeow Feb 18 '12 at 16:30
8  
Xcode -> Preferences -> Downloads -> Install Command Line Tools. See my answer below. –  elsurudo Apr 11 '12 at 15:05

Just download the newest version from here: http://code.google.com/p/git-osx-installer/

Install it, open up a new terminal, and it works like before :D

share|improve this answer
    
Link to the package list: code.google.com/p/git-osx-installer/downloads/… –  Daniel Jul 21 '11 at 9:30

Same issue here, downloaded and installed the snow leopard version from google code and off I went. Needed to quit and re-open terminal though...

All is well again..

share|improve this answer

I think you will find that Git is still installed on your system. It looks like the PATH is just messed up. Check to see if /usr/local/git still exists on your system.

I just added the following to my ~/.bashrc file and everything is back to normal.

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

To be more specific, this site - http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html - details the difference between .bashrc and .bash_profile. If you use Mac's terminal with Git, then adding the above PATH specification to your .bash_profile will do the job. Of course, you'll have to close the Terminal window and open a new one because the .bash_profile file is loaded on a Terminal window's opening.

In summary, adding this to .bash_profile would work too.

share|improve this answer
    
That's exactly what I did too and git is working again. –  Kleber S. Jul 22 '11 at 5:17
2  
This is the correct solution. It's only the PATH that is messed up. The other answers people have given here are workarounds, rather than the solution. –  Dan Smart Jul 22 '11 at 8:28
    
I tried doing this, but still get a command not found error when trying git add. Do I need to completely restart my computer to get the path to update? –  EmmyS May 9 '12 at 16:26
    
Did you restart your terminal? Or source your .bash_profile file? Just type source .bash_profile in your terminal while in your home dir –  Aaron Chambers May 10 '12 at 14:08
    
yes, I restarted my terminal. I'm not sure what source means, but the answer by ing0 below (minus the reinstall of git) worked for me. Possibly my bashrc file was in the wrong place. In any case, it's working now. –  EmmyS May 10 '12 at 16:37

Step 1: Reinstall git (I just installed the Snow Leopard version from here) if it's not in:

/usr/local

Step 2: Open Terminal and do the following:

cd /etc

sudo nano bashrc

Then in nano at the top of the file write (as aaron suggested)

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

Press Ctrl+X to quit nano and press Y to save. Then exit terminal and reopen and git should be working for you.

share|improve this answer
    
You shouldn't need to reinstall Git. I believe you will find it is still installed. Check /usr/local/git –  Aaron Chambers Jul 21 '11 at 10:52
    
Mine had gone completely. So I reinstalled. Like I said, if it's there then there's no need to do it! –  ing0 Jul 21 '11 at 11:23
    
This worked for me as well. Everything worked fine before the Lion upgrade--this was a quicker solution than downloading the 4+ GB XCode. –  jnunn Jul 21 '11 at 15:03

If /usr/local/git already exists, you'll need to either add it to your $PATH or make a symlink placing the symlink inside a directory that is in your existing PATH.

A common practice is to make /usr/local/bin if it doesn't exist and add a link:

sudo -s
mkdir -p /usr/local/bin
ln -s /usr/local/git/bin/git /usr/local/bin/git
exit
share|improve this answer
4  
this is the proper answer –  TheLindyHop Jul 21 '11 at 17:10
    
/usr/local/git exist but I get: "ln: /usr/local/bin/git: No such file or directory." –  Kevin Tsoi Jul 21 '11 at 21:41
    
This is what we needed I guess. It does what it should do. Thanks! –  Ren-D Jul 22 '11 at 8:02
1  
This is exactly what fixes the problem; this should have been marked as the correct answer –  Doug Molineux Jul 30 '11 at 4:32
1  
Even though the majority of people will have git installed in /usr/local/git perhaps the OP appreciated thhe general answer. Anyone who wants to re-ask this question stating the chosen answer here didn't work could then select this answer when it gets provided. No harm in two valid questions with two valid answers. –  bmike Sep 11 '11 at 20:40

I solved it by following advice on this site:

http://blogger.forgottenskies.com/?p=740

It was just a pathing issue. To be honest, I expected a whole lot more issues. The upgrades are getting smoother. I remember when I upgraded from Tiger to Leopard, just about everything "open source" broke..

share|improve this answer

When there is git path already,

just add directory to your PATH variable.

echo 'export PATH=/usr/local/git/bin:$PATH' >> ~/.profile

share|improve this answer

I fixed it by downloading and reinstalling git from here.

share|improve this answer

From StackOverflow:

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

then run source ~/.bash_profile in Terminal

Link to the post there: http://stackoverflow.com/questions/6810059/git-on-mac-os-x-lion/6810082#6810082

share|improve this answer

If you are using brew, just run this command from the terminal.

brew install git

share|improve this answer

I used the App Store to install Xcode and it just gives you an all in one app blob. However it DOES have other apps and installers in it. I just needed git so the path from that is export PATH=$PATH:/Applications/Xcode.app/Contents/Developer/usr/bin

Its a bit of a hack, but I don't use Xcode for a lot of stuff. Add to your bash config as other posters described and your good to go

share|improve this answer
    
Instead of messing with $PATH it's actually easier to install the Command Line Utilities from within Xcode and use /usr/bin/git afterwards –  patrix Nov 5 '12 at 15:44

If you have XCode installed, the best solution is Xcode -> Preferences -> Downloads -> Install Command Line Tools.

This put git (among other things) at /usr/bin/git.

If you don't have Xcode installed, then installing it just for git would definitely be overkill.

share|improve this answer
1  
Thanks for this - definitely the easiest way to go if you already have XCode installed. –  Glenn Barnett Jul 3 '12 at 2:16

You don't need to modify the path or install the Xcode command-line tools. Just use the "xcrun" utility from the Terminal: http://www.cocoanetics.com/2012/07/you-dont-need-the-xcode-command-line-tools/

share|improve this answer
    
Welcome to Ask Different! It's okay to include a link, but please summarize or excerpt it in the answer. The idea is to make the answer stand alone. Please take a look at the FAQs for more info. –  gentmatt Sep 27 '12 at 9:00

This happened because git stop being part of the $PATH (for some migration reason).

There is a very simple way of fixing this in OS X:

In OS X, you can add variables to $PATH by changing the file

/etc/paths

so, you can put back git doing the following:

sudo vim /etc/paths

add /usr/local/git/bin to the end of the file, save, and exit. Restart shell. Git should work.

share|improve this answer
1  
/etc, are you sure? Shouldn't this rather be /usr? –  patrix Aug 28 '13 at 15:36
1  
@patrix Fixed. thanks! –  J. C. Leitão Aug 28 '13 at 15:58

Your Answer

 
discard

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