I have installed the newest version of git (1.8.3) using homebrew but when I type
in my terminal, it prints:
git version 220.127.116.11 (Apple Git-33)
What should I do to replace the old version of git with the new one?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.Sign up to join this community
All the tricks mentioned here in several answers are not necessary anymore on Intel Macs running macOS Sierra or higher with the latest Homebrew. Forget
export PATH="..." and modifications to
You simply do
brew install git
and you're done.
To confirm, open a new terminal window/tab and type
Please don't forget to open a new window. Terminals that were open before you started to
install will not inherit any changes.
Ok, I'm ready to get serious about scm.
$ git --version git version 1.9.5 (Apple Git-50.3)
Nope, that's not what I wanted. I <3 homebrew, so:
$ brew install git
$ git --version git version 1.9.5 (Apple Git-50.3)
Doh! (scratches head)
$ which git /usr/bin/git
Ah, Apple's git is in /usr/bin, so it trumps the homebrew one. What to do?
(A) Just rename Apple's binary
(B) Let homebrew-managed one take precedence:
[edit PATH export e.g. in ~/.zshrc (oh-my-zsh + iTerm2 FTW! /tangent)]
[specifically: move /usr/local/bin/git: before /usr/bin:]
... and/or (e.g. to more broadly let homebrew stuff trump system installs, and have the precedence apply to all shells and users) also edit /etc/paths file, [moving /usr/local/bin above /usr/bin]
But assuming just the simplest / least invasive approach:
$ sudo mv /usr/bin/git /usr/bin/git-apple
Did it work?
$ which git /usr/local/bin/git
So far so good, now the moment of truth:
$ git --version git version 2.2.1
w00t! :) Time to go read http://git-scm.com ! :)
Once you've installed the latest git via brew (
brew install git), run this one-liner (as suggested by
brew doctor) if it isn't already there:
echo "export PATH=/usr/local/bin:$PATH" >> ~/.bash_profile
Then quit Terminal an open it again (restart your bash session). You need to do this even if your PATH was already correct, as ZSH and Bash cache the contents of PATH (see the documentation on the built-in command
That should fix things really fast.
When you type
in Terminal.app or console, your comment on another question indicated the version it returns is the git in /usr/bin/git
If you installed Xcode 4.5 (and newer), and type
xcrun git --version
in Terminal.app or console, the version it returns is the git in the Xcode app bundle.
If you are using Homebrew to install and update git, the simplest solution is to
rename the original location by renaming it using mv. For example
sudo mv /usr/bin/git /usr/bin/git-ORIGINAL
create a soft link using 'ln -s' to the git binary you installed with Homebrew.
Note that MattDMo has a better solution in the comments.
When you use
brew install git for the installation, notice that it install
==> Summary 🍺 /usr/local/Cellar/git/2.29.2: 1,480 files, 39.7MB
You will also get an error, which appears earlier in the log and probably you missed it:
==> Downloading https://homebrew.bintray.com/bottles/git-2.29.2.big_sur.bottle.t Already downloaded: /Users/chadjinik/Library/Caches/Homebrew/downloads/08165d120fcebc7823c487a6778b2ea0e67fd2cd9177d6e7d656268f474ab5da--git-2.29.2.big_sur.bottle.tar.gz ==> Pouring git-2.29.2.big_sur.bottle.tar.gz Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local Could not symlink bin/git Target /usr/local/bin/git already exists. You may want to remove it: rm '/usr/local/bin/git' To force the link and overwrite all conflicting files: brew link --overwrite git
brew link --overwrite git
and you should be good.
You have to rename the original git by apple in
/usr/bin/ to e. g. git-org since
/usr/bin is normally before
/usr/local/bin in your path directory where the brew stuff is.
cd /usr/bin sudo mv git git-org
and do not forget to link the brew git
brew link git
This assumes that
/usr/local/bin is in your
$PATH environment variable. If you still have problem try to run
and fix the problems mentioned there.
Ok so I ran
brew doctor and I saw this:
Warning: You have unlinked kegs in your Cellar. Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on those kegs to fail to run properly once built. Run `brew link` on these: git
Of course I run
brew link git. Then I got:
Error: Could not symlink bin/git Target /usr/local/bin/git already exists. You may want to remove it: rm '/usr/local/bin/git' To force the link and overwrite all conflicting files: brew link --overwrite git To list all files that would be deleted: brew link --overwrite --dry-run git
brew link --overwrite git and it worked!
If you are installing git from git-scm.com directly and would want to use the latest downloaded git instead of apple(old) version of git.
git --version, if it returns Apple old version of git then proceed below
cd ~(change directory to your home directory)
i(to insert text in vi editor)
export PATH......., press enter on top of the export and type the following:
export PATH=/usr/local/:$PATH(Pay extreme caution with
PATHvariable do not mess it up else it will cause problems for your OS) (hopefully new git should be installed in
:wq(to save the
git --version(you should see new version)