0

I wanted Mac OS to use my homebrew version of git after brew install git. So I mistakenly renamed my Apple Default git by doing:

$mv /usr/bin/git /usr/bin/git~apple
$ git --version
git version 2.25.0

I am attempting to uninstall the homebrew version of git, and revert back to the Apple version of git.

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin

$ which git
/usr/local/bin/git

$ brew uninstall git
Uninstalling /usr/local/Cellar/git/2.25.0... (1,523 files, 45.6MB)
$cp /usr/bin/git~apple /usr/bin/git

$mv /usr/bin/git~apple /usr/bin/git

$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin

$ which git
/usr/bin/git

$ git --version
-bash: /usr/local/bin/git: No such file or directory

It seems like after uninstalling homebrew and moving the original git file back to its location, which git finds the correct $PATH for git, but git --version cannot find git. How do I properly restore the original Apple version of git?

1 Answer 1

1

Shells remember the paths to commands you've executed during a session. You can use the hash command to manage the remembered paths (from man bash):

hash [-lr] [-p filename] [-dt] [name]
For each name, the full file name of the command is determined by searching the directories
in $PATH and remembered. If the -p option is supplied, no path search is performed, and filename
is used as the full file name of the command. The -r option causes the shell to forget all 
remembered locations. The -d option causes the shell to forget the remembered location of each
name. If the -t option is supplied, the full pathname to which each name corresponds is printed.
If multiple name arguments are supplied with -t, the name is printed before the hashed full pathname.
The -l option causes output to be displayed in a format that may be reused as input. If no arguments
are given, or if only -l is supplied, information about remembered commands is printed. The 
return status is true unless a name is not found or an invalid option is supplied.

Run hash -r to clear any command paths your shell has cached (or hash -d git to just remove the entry for git). Opening a new Terminal tab/window has the same effect.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .