This blog post is for a very specific group of people who cared enough to notice that git command line tool is not working on their brand new MacBooks with Mountain Lion! If that sentence didn’t make sense to you, then you are probably at the wrong place. I got my new Mac last week and I wanted to clone some code from Github. So I opened the terminal to clone it and behold, “git” is apparently not a recognized command! I have already installed the latest developer preview of Xcode (version 4.6 DP3), so what went wrong here? It turns out that we need to manually install the git command line tools. We still live in a world where git is not an integral part of all the systems! Xcode 4.6 doesn’t install the command line tools by default, and Git is one of the tools included in these command line tools. Anyway, there’s a simple fix for it.
If you are still reading this, then I assume you would have already tried this method. But just for the sake of completeness, I will describe it. If you don’t have Macports installed, you can install it from here. Once you install it, open the terminal and type the following:
$ sudo port install git-core +svn +doc +bash_completion +gitweb
That should install git for you. Make sure your PATH environment variable contains the path to git. Follow these steps:
- Open your ~/.bash_profile using the following command:
$ sudo vi ~/.bash_profile
- Add this line to the “bash_profile” file:
- Save and close the file. Then type the following on the terminal to make sure the changes take place:
$ source ~/.bash_profile
Open the terminal and try to git clone something. If that doesn’t work, then read on, there’s another method!
If you are reading this section, then the above method probably didn’t work for you. You may also have tried a couple of other methods as well. If nothing has worked for you yet, the following steps definitely will. Make sure you have Xcode installed, and then do the following:
- Open Xcode
- Select Xcode -> Preferences
- A new window will pop up. Select “Downloads” tab on the top
- You should see “Command Line Tools” listed there. Click on “Install” located on that line.
- Go back and check on your terminal. Git should now be up and running!