After installing Git, run this command in the terminal:
git --version
If you are prompted to install XCode Tools, see your instructors during Help Hours, or follow these instructions to fix the problem on your own.
It is not necessary to install XCode. The solution is to update your OS X execution path.
Adding the directory to the path will prevent Mac OS X from asking you to install XCode each time you type git in the terminal.
The Cause of the Problem
Your Mac expects expects Git to be installed in /usr/bin/git, which is where XCode installs it.
Git’s official installer puts Git in /usr/local/git/bin/.
To stop OS X from prompting you to add XCode, you need to edit a file named .bash_profile file in your home directory and set the PATH there.
.bash_profile controls various shell environment preferences including PATH.
You can resolve this conflict by placing /usr/local/git/bin before /usr/bin in the execution PATH.
There are two ways to do this– pick one of the following:
Fix the Problem, Using the Shell:
Open the terminal app, and run these two commands:
echo "PATH=/usr/local/git/bin:\$PATH" >> ~/.bash_profile
source ~/.bash_profile
Or, Fix the Problem, Using Nano:
Launch Nano
Nano is a command-line text editor built-in to Unix.
- Enter the cd command without any arguments, to move to your home directory.
- Enter the pwd command to verify that you are in your home directory.
- Enter the nano .bash_profile command.
This will open the file in Nano.
The control key is referred to using ^. For example, ^X means “hold down the Control key and press the x key”.
Most of the important commands are listed at the bottom of the Nano screen.
- Add the following line to .bash_profile:
export PATH="/usr/local/git/bin:$PATH"
- Save the changes in Nano: control-O.
- Exit Nano: control-X
- Notify the shell of your changes to PATH.
Unix dot-files are read by the shell when you first start the terminal, or login to a remote computer.
If you change .bash_profile, run this source command to have the changes take effect:
source ~/.bash_profile
- Now you should be able to run Git without XCode:
which git
git --version
Optional Readings
The Unix PATH Variable
PATH is an environment variable on Unix systems (OS X) and Windows, specifying a set of directories where executable programs are located.
For example, when you run any git command such as the following:
git --version
The shell uses the PATH variable to find where Git is installed on your computer, and then runs it.
Problems emerge when you have Git installed in a different place than what is in the PATH.
Other Unix Commands
which — locate a program file in the user’s path.
command -v git — same.
whereis — locate programs. whereis checks the standard directories for the specified program, printing out the paths of any it finds.
echo $PATH — display the value of the PATH variable.
Let’s use these commands as follows:
- echo $PATH
This command shows what is in the PATH.
Example: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Example: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin
- which git
This command shows us just that part of the PATH relevant to Git.
Example: /usr/bin/git
Example: /usr/local/git/bin/git
- whereis git
This command shows where Git is installed on your computer. Note: it could be installed in more than one place, depending on your history of installing Git.
Example: /usr/bin/git
Example: /usr/local/git/bin/git