21

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?

9 Answers 9

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Ah!, well that's something...but I don't know what to do. Please check the edited question.
Do I need to logout/login to make these changes visible or should it just "work"?
OS X sources your profile every time you open a terminal, I think.
this worked for me in 10.6.4 as well. I had just installed MacPorts
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?
|
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/

2 Comments

Thanks, this was the fast and easy way to fix it!
Also consider @lorddev's answer: with Xcode, set up bash profile alias git='xcrun git'
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.

4 Comments

Perfect! Updating the ~/.profile file did not work for my setup.
I didn't have any .bash_profile to begin with, so I fail to see how deleting it would fix this.
Under 10.8, this seems to be the /etc/paths file. Just edit it with sudo nano /etc/paths
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." :)
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.

Comments

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 

Comments

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.

Comments

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!

Comments

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

Comments

0

By default git is not installed on new MacOS. You have to install Command Line Tools for Xcode

If you install Homebrew using the following command in your terminal, that can take care lots of these tools.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" 

Alternative way of that is to install XCode manually from the App Store.

If all goes well you will see the following output in your terminal:

Warning: /opt/homebrew/bin is not in your PATH. Instructions on how to configure your shell for Homebrew can be found in the 'Next steps' section below. ==> Installation successful! 

And then you can check the git version using the following command:

git --version 

and output should be something like:

git version 2.39.5 (Apple Git-154) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.