Git from command-line after installing Xcode on OS X Lion
Xcode 4.3.x or newer comes with Git but the problem is when you install Xcode on your machine (OS X Lion or newer), Git’s path won’t be added to the user path which means if you run git from your command-line, your system will say:
-bash: git: command not found
Xcode’s installation of Git is at the following location on your machine:
/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/
With the git binary sitting here:
/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git
To add this binary to your path (which will allow you to run “git” from any directory on your system), go to terminal and type this command:
export PATH=”/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/”:$PATH
There is one caveat to this approach and that is the PATH will only be changed in your current running instance of terminal. As soon as you close terminal and open it again, you will have to enter the above command again to get access to the git app. So what is the proper solution? You will have to add the above “export” command to the .profile file in your home directory. The .profile file gets read every time you open terminal. So open a terminal instance and type the following command:
cd ~/
And then type this command:
ls -la | grep “.profile”
We are trying to find out if we already have a file named .profile in our home directory. If after running the above command you won’t see anything getting printed to the terminal, use the following command to create a new .profile file. If you already have a .profile file, skip this command:
touch .profile
Now open the .profile with this command:
open .profile
Now add the git path to the PATH variable in the .profile file so that your .profile content will look something like this (it really depends on what you already have in this file. I am assuming your .profile file didn’t exist until now and you just created it):
export PATH=”/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/”:$PATH
Save your changes to the .profile file and close terminal and open it again. Now whichever directory you are in, in terminal, you can use the git command. Good luck.
Thanks, this solved my git problem with a new install of Lion. Two tips to others: (1) if you copy/paste the commands directly from this site, make sure to replace the quotes with the proper characters. Mine pasted in as curly quotes that weren’t recognized properly by terminal. (2) Your profile file may be named “.bash_profile” (instead of just “.profile”).
Thanks for the tip :-p
Ty m8 ~ saved my day!
I’m glad. Thanks for visiting
Amazing! Thank you for this very clear step-by-step explanation. It certainly saved me hours
Thanks for leaving a reply
I’m glad it was useful to you.
Hi VandadNP,
Thanks for the advice. After tweaking this, I found it a bit more convenient to turn the problem around. Since access to /usr/bin in in the system $PATH by default, I simply made a symbolic link to git from within the /usr/bin folder.
cd /usr/bin
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git git
Natural benefit is that it’s available in every Terminal session without extend $PATH or .profile
Good point. Symlinks will do too.
I added the following to .profile:
export PATH=”/Applications/Xcode.app/Contents/Developer/usr/bin/”:$PATH
This gives you xcodebuild, xcrun, SetFile and other useful tools. Git included.
Great point. Thanks.
Pingback: Git und Xcode | nerdy stuff
Looks like Xcode 4.4 has a hardlink for git into /usr/bin now. See, they listen!
You don’t need to modify the path or install command-line tools — just use “xcrun”:
http://www.cocoanetics.com/2012/07/you-dont-need-the-xcode-command-line-tools/