Wednesday, April 20, 2011

git clone fails when cloning from OSX

if you try to git clone a project where the remote host is osx you'll have issues. The problem is interactive shells get their path from /etc/paths + /etc/paths.d + /etc/bashrc + anything you put into your ~/.bash_profile (in my case I just soft link my .bash_profile to .bashrc so I dont go crazy switching back and forth between Linux and OSX).

Non-interactive shells do not get the paths from /etc/. So when cloning you'll get

bash: git-upload-pack: command not found
fatal: The remote end hung up unexpectedly


This means ssh couldn't find git-upload-pack. A quick solution to this is adding the following line to your ~/.bash_profile --
[ "$PATH" =~ "git" ] || export PATH=$PATH:/usr/local/git/bin

this will only add the path if its not already present. Which means interactive shells wont have the same path twice, but non-interactive shells will get it too.