"/usr/local/bin/git": error=2, No such file or directory Android Studio

Rohit Tigga picture Rohit Tigga · Jan 4, 2015 · Viewed 9.7k times · Source

So I opened the GitHub Application for the Mac and I was prompted with this:

GitHub for Mac no longer installs Git

OS X 10.9 and later includes Git, so GitHub for Mac will no longer install Git as part of its command line tools.

The version of Git you have installed through GitHub for Mac is no longer supported. It's recommended that you uninstall it as soon as possible.

[ Uninstall Git Later] [ Uninstall Git Now ]

I went ahead and uninstalled Git because I was under the impression that I was supposed to (GitHub for Mac no longer installs Git message)

Now I share my Android Studio Project via Github. Whenever I try to push changes the my project or do anything I get this error message:

Can't start Git: /usr/local/bin/git Probably the path to Git executable is not valid. Fix it.

And this message:

Error running git “Cannot run program ”git": error=2 No such file or directory

I've done research but I am unable to fix it.

I entered which -a git in the terminal and I got:

/usr/local/bin/git

which is set is the Android Studio Project sync with Github.

How can I resolve this error? Why is this occurring?

Answer

Scott Zhu picture Scott Zhu · Jan 15, 2015

The reason why this is occurring is that:

You have uninstalled the Git that the Android Studio is pointing to, which was installed by Github for Mac, and was located in /usr/local/bin/git. But now you have deleted it, so the Android Studio can't find it of course. Let's call it GitHub-Git.

However, as mentioned by Github for Mac which is correct,

OS X 10.9 and later includes Git, so GitHub for Mac will no longer install Git as part of its command line tools.

It means there is another Git pre-installed in your system for OS X 10.9 and later, let's call it System-Git. You can prove it by opening your Terminal, and type in the git command, as you can see below: enter image description here

So the Git is still working!! Even after you have uninstalled your GitHub-Git. Why? Because Terminal is using the System-Git. Ok, so there's still git on your Mac, all you have to do is tell the Android Studio where the git is!

Solution!!:

  1. Find the location of System-Git. In Terminal, type in whereis git. In my case, the location of my System-Git is /usr/bin/git enter image description here
  2. In your Android Studio, go to Preferences and search for the keyword git enter image description here Here you see you got a WRONG path for the git /usr/local/bin/git, which should be /usr/bin/git. Just replace it with a right one, press Apply.

Now, everything should be working.