20

I am receiving this error when I try to use git lately. I'm not exactly sure when the error started as I rarely use git. I used to use it. I didn't change anything about it or my machine that I know of. Now it doesn't work.

I've gone through and reinstalled the latest version using this installer, and I still get the same error in terminal.

Anyone heard of this before? The installer runs just fine, no errors, but it still doesn't recognize the "git" command in terminal.

I'm running OS 10.5

EDIT

Per a response down below which pointed me to my PATH variable I think that's the issue. I installed MacPorts at one point, which changed my .profile I have no idea how to change it back though. My old .profile was this:

alias g='git'
export PS1='$(git branch &>/dev/null; if [ $? -eq 0 ]; then \
echo "\[\033[00m\]$(git branch grep ^*sed s/\*\ //) "; fi)\$\[\033[00m\] '
export LC_CTYPE=en_US.UTF-8
export PATH=$PATH:/usr/local/bin

My new .profile is this:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export MANPATH=/opt/local/share/man:$MANPATH

How can I make those two files become one?

pnkfelix
  • 3,770
  • 29
  • 45
James P. Wright
  • 8,991
  • 23
  • 79
  • 142

8 Answers8

26

Had the same issue on mountain lion.

If yo're using XCode, run it. then go to XCode->preferences and install "Command Line Tools".

thats it, worked for me.

http://www.hongkiat.com/blog/mountain-lion-git-fix/

Alon Shacham
  • 299
  • 3
  • 6
26

From the page you linked to:

/usr/local/git/bin

Is that in your PATH?

Open ~/.profile in your favorite editor and add the line

export PATH=$PATH:/usr/local/git/bin

This appends the item to your PATH variable (separarated by colons), so it's compatible with other commands that modify the path.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
  • Ah!, well that's something...but I don't know what to do. Please check the edited question. – James P. Wright Dec 02 '09 at 21:45
  • Do I need to logout/login to make these changes visible or should it just "work"? – James P. Wright Dec 02 '09 at 21:49
  • OS X sources your profile every time you open a terminal, I think. – Josh Lee Dec 02 '09 at 21:50
  • this worked for me in 10.6.4 as well. I had just installed MacPorts – Thomas Sep 01 '10 at 19:04
  • 10.5 Server, open directory (LDAPv3/127.0.0.1) user [username]. Home directory is set to afp://localhost/Users/[username] (from Workgroup Manager). on a remote SSH from my work computer, "cd ~" then "pwd" confirm that the home directory of [username] is indeed /Users/[username]. Echoing $PATH from said SSH connection shows only '/usr/bin:/bin:/usr/sbin:/sbin', although the .bash_profile file I created at the home directory clearly adds '/usr/local/git/bin'. Remote Git commands via SSH from work computer return 'command not found'. What am I missing? – Nicolas Miari Jun 13 '12 at 12:40
  • I just want to write code; why do I have to be a server admin? When will the dark ages of the command line be finally over? – Nicolas Miari Jun 13 '12 at 12:45
  • My git is installed at /usr/local/bin/git instead of the given /usr/local/git/bin – pal4life May 27 '15 at 12:24
11

Another way to approach this is to check to see if you have an /etc/paths.d/git file. The OSX installer should have created that file containing:

/usr/local/git/bin

so that it is picked up without any .bash_profile needed, or at least no special entries in your .bash_profile, or .profile in your case.

I just tested deleting my .bash_profile and opening a fresh shell window and I'm still able to resolve the git command.

Courtney Faulkner
  • 2,010
  • 16
  • 17
  • Perfect! Updating the ~/.profile file did not work for my setup. – leviathan Dec 05 '11 at 14:11
  • I didn't have any .bash_profile to begin with, so I fail to see how deleting it would fix this. – Nicolas Miari Jun 13 '12 at 12:39
  • 1
    Under 10.8, this seems to be the /etc/paths file. Just edit it with sudo nano /etc/paths – Bjinse Jan 08 '14 at 09:35
  • Yeah, both /etc/paths and /etc/paths.d/git will work. The path_helper utility will blend the contents of /etc/paths and /etc/paths.d/* and de-dupe them. I think the reason to pick /etc/paths.d/* is just to have a reminder of what process needed that path, if it isn't readily apparent. Otherwise, I don't think it matters which is used. See `man path_helper` for more info. Also, this whole question should now be answered with "install and run homebrew to keep git up to date." :) – Courtney Faulkner Jan 09 '14 at 01:57
8

What worked for me was

  1. Installing the latest version of Xcode from the App Store
  2. Running alias git='xcrun git' per this guy.
devlord
  • 4,054
  • 4
  • 37
  • 55
5

In case people still get this problem, make sure the /usr/libexec/path_helper is executable. I had this problem when I installed Prezto.

sudo chmod ugo+x /usr/libexec/path_helper
tquach
  • 51
  • 1
  • 2
2

Navigate to your home directory:

cd ~

You can verify you are in the correct directory by printing your working directory:

pwd

It should output something like: /user/YOUR_USER

Then open up your bash profile:

vi .bash_profile

You should see something like the following:

Bash Profile VI

Then press 'i' to enter insert mode

insert mode

Then add your export to the file(You can use COMMAND+c and COMMAND+v to copy paste):

export PATH=$PATH:/usr/local/git/bin

Then press the 'esc' button -> then type in the following to write your changes and quit:

:wq

Then press enter.

Next, you will need to close and quit the terminal and then open a new one.

anataliocs
  • 10,427
  • 6
  • 56
  • 72
1

In my case, there was nothing wrong with my path, but whether XCode is correctly installed or not.

In the Terminal (Applications > Utilities > Terminal), type and run:

xcode-select --install

This command will download and install XCode Developer Tools and you won't see that message again.

Or, depending on where you problem lies, running the following command may also help:

xcode-select --reset

Hope it helps!

Luiz Dias
  • 1,947
  • 17
  • 22
0

Since this was the top result in my Google search for: "git-clone: command not found" , I would add in my case I only needed to remove the dash, i.e. "git clone" instead of "git-clone" and that resolved my issue, I was following a tutorial where dash appeared to be used

Carl
  • 11
  • 2