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.

About these ads

15 thoughts on “Git from command-line after installing Xcode on OS X Lion

  1. 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”).

  2. 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

  3. 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.

  4. Pingback: Git und Xcode | nerdy stuff

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s