I have installed the newest version of git (1.8.3) using homebrew but when I type

git --version

in my terminal, it prints:

git version (Apple Git-33)

What should I do to replace the old version of git with the new one?

  • # In Terminal, Install it ``` brew install git ```` # In $HOME/.zshrc you need to add path to make it available PATH="$(brew --prefix)/opt/git/libexec/git-core:$PATH" # In Terminal reload it source ~/.zshrc # Test it which git /usr/local/opt/git/libexec/git-core/git
    – Gedw99
    Commented Mar 3, 2023 at 12:26

14 Answers 14


Status 2024

All the tricks mentioned here in several answers are not necessary anymore on Macs running macOS Sierra or higher with the latest Homebrew. Forget export PATH="..." and modifications to ~/.bash_profile.

You simply do

brew install git

and you're done.

To confirm, open a new terminal window/tab and type

git --version

Please don't forget to open a new window. Terminals that were open before you started to install will not inherit any changes.

  • Why then the need to open a new window/tab?
    – nohillside
    Commented Jul 6 at 20:41
  • @nohillside - While technically true, the takeaway is that no additional commands are required to manually manipulate the PATH. When Homebrew is installed on Apple Silicon, PATH is already updated to include /opt/homebrew/bin/, and this comes before any other elements defined in the PATH. As such, when installing git via brew no additional work is necessary, and the first binary to be found when the command is entered is /opt/homebrew/bin/git. For Intel Macs, /usr/local/bin is used, but this still comes before /usr/bin, which is where Apple's git lives.
    – retrobit
    Commented Jul 6 at 20:51
  • @nohillside - If you installed Homebrew in the same session, then yes, you are updating the PATH and you should need to either re-source or open a new session for it to be reflected. Again, this is not manual manipulation of the PATH and it is automated by the Homebrew installation script.
    – retrobit
    Commented Jul 6 at 21:03
  • Your answer seems to be incomplete then, there is no mentioning of installing brew. Which is fine IMHO, but then there shouldn‘t be a need to open a new window if all one has to do is brew install git.
    – nohillside
    Commented Jul 6 at 21:43
  • I should mention I am using fish and this behavior could be entirely different based on Homebrew's installation script and how the shell manages PATH. In my case this was tested on a new session, many sessions after Homebrew was already installed 🙃
    – retrobit
    Commented Jul 7 at 2:27

If on Intel, add

export PATH="/usr/local/bin:${PATH}"

if on ARM/M1, add

export PATH="/opt/homebrew/bin:${PATH}"

in ~/.bash_profile followed by

source ~/.bash_profile

solved the problem for my user.

  • 22
    If you want the change persistent across users, you can move /usr/local/bin above /usr/bin in /etc/paths.
    – kevin
    Commented Nov 12, 2013 at 5:08
  • 4
    This is the solution proposed by Homebrew itself when running brew doctor to diagnose the issue
    – VoxPelli
    Commented Dec 4, 2013 at 14:22
  • 12
    Remember to restart terminal! Didn't occur to me until i saw Juan Diego Gonzales's comment below
    – Souleiman
    Commented Jun 30, 2015 at 14:33
  • 4
    @Souleiman: Restarting isn't necessary. source ~/.bash_profile will re-read that. Restarting is just probably faster/easier. :)
    – user2702
    Commented Oct 5, 2015 at 23:12
  • 3
    brew link --overwrite git worked for me
    – wickdninja
    Commented Feb 20, 2019 at 3:50

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

All set?

$ git --version
git version 1.9.5 (Apple Git-50.3)

Doh! (scratches head)

$ which 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

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 ! :)

  • PS Rel to comments about risks of editing /usr/bin: IMHO it's NBD. (Tho I do like Global nomad's sugg. to do "sudo ln -s /usr/local/bin/git /usr/bin/git" ... which ensures that anything calling "/usr/bin/git" explicitly will get your brew-managed one. But my take is, installing git implies you're taking ownership of git on your system. Worries about unknown processes using an older, alternate version of git, might be misplaced. I recommend keeping up to date w/ git versions (for security, not just features), and managing it yourself. Homebrew makes this easy. /$0.02
    – cweekly
    Commented Jun 17, 2015 at 18:41
  • This didn't work for me, to undo it, just do: sudo mv /usr/bin/git-apple /usr/bin/git . Juan Diego Gonzales's comment worked. (basically, follow the accepted answer then restart terminal).
    – Souleiman
    Commented Jun 30, 2015 at 14:33
  • 1
    Even with which git pointing to /usr/local/bin/git, this didn't work for me. To solve this, I had to uninstall the GitHub Mac app.
    – Ben
    Commented Dec 22, 2015 at 18:28
  • 8
    MacOS 10.12.5: sudo mv /usr/bin/git /usr/bin/git-apple mv: rename /usr/bin/git to /usr/bin/git-apple: Operation not permitted Commented Jun 19, 2017 at 13:45
  • 3
    Just use brew doctor. In 2020, it recommended brew link —overwrite git Commented Jan 18, 2020 at 16:03

I tried this and it works for me.

brew link --overwrite git
  • 1
    As of April 2023, this worked on M2. Commented Apr 24, 2023 at 1:56

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 hash).

That should fix things really fast.

  • 1
    How does this differ from the accepted answer?
    – mmmmmm
    Commented Jan 21, 2014 at 13:52
  • 6
    In my case, I didn't know I had to restart Terminal, so that part may help some people. Is faster than the accepted because of the one liner. If it's a competition I think my answer is misplaced. Otherwise I think it contributes. (Tell me if you want me to make an edit instead of this). Commented Jan 22, 2014 at 0:51
  • You do that one liner when you install Homebrew
    – mmmmmm
    Commented Jan 22, 2014 at 12:19
  • 7
    I found this answer helpful. Restarting the terminal is a non-obvious issue for many people unfamiliar with the workings of .bash_profile, and a gentle reminder for the rest of us.
    – Magne
    Commented Jan 28, 2015 at 9:59
  • @JuanDiegoGonzales Excellent observation! I was wondering the exact same thing after I installed git and didn't know why. After the cache hint, I did a bit more research: unix.stackexchange.com/q/5609/52921
    – stratis
    Commented Dec 7, 2015 at 11:24

When you type

git --version

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

  1. make sure you have admin rights as you'll be asked for the password for the admin
  2. rename the original location by renaming it using mv. For example

    sudo mv /usr/bin/git /usr/bin/git-ORIGINAL

  3. 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.

  • 11
    Please don't do this - you really shouldn't be messing around with /usr/bin, as it's possible that other programs you don't even know about depend on vagaries associated with a particular version. The easiest solution, without moving anything, is to add /usr/local/bin to your $PATH environment variable before /usr/bin - IIRC, homebrew installs to /usr/local/bin
    – MattDMo
    Commented Jun 3, 2013 at 17:03

When you use brew install git for the installation, notice that it install git under:

==> 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

Just run:

brew link --overwrite git

and you should be good.


Install git with brew, the run this.

brew link --force git

Close and reopen terminal to run which git.

  • 1
    How does that change the default path?
    – mmmmmm
    Commented Apr 15, 2017 at 6:46
  • This worked for me to override xcode's git.
    – surj
    Commented Feb 15, 2018 at 23:59
  • I got an error when running this but brew link --overwrite git worked
    – wickdninja
    Commented Feb 20, 2019 at 3:48

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

brew doctor 

and fix the problems mentioned there.

  • 3
    Don;t rename or chnage things in /usr/bin as it could break Apple thigs and they will get chnaged when you do a system or XCode update. use the path which is what it is designed for,
    – mmmmmm
    Commented Jun 3, 2013 at 14:16
  • 3
    I think it would be much easier to add /usr/local/bin (homebrew's install directory, IIRC) to the $PATH ahead of /usr/bin instead of mucking around with renaming and backing up, etc.
    – MattDMo
    Commented Jun 3, 2013 at 17:05

Do a simple alias to avoid changing path:

alias git=/usr/local/bin/git
  • Yep! This is what I ended up doing too. I didn't want to change the PATH precedence or any other hacky stuff. Commented Mar 21, 2022 at 23:55
  • this is the only thing that worked for me. even changing path didn't work for me - possibly related to Xcode Command Line Tools
    – ehacinom
    Commented Jul 6, 2022 at 6:47

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:

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

I ran 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.

  1. Install git from git-scm.com
  2. Most probably new git will be installed in /usr/local/bin/git
  3. Try git --version, if it returns Apple old version of git then proceed below
  4. cd ~ (change directory to your home directory)
  5. type vi .bashrc
  6. Use i (to insert text in vi editor)
  7. If you find a line with export PATH......., press enter on top of the export and type the following: export PATH=/usr/local/:$PATH (Pay extreme caution with PATH variable do not mess it up else it will cause problems for your OS) (hopefully new git should be installed in /usr/local/git)
  8. Press esc
  9. Enter :wq (to save the .bashrc file)
  10. Exit out of terminal and start new terminal
  11. Now try git --version (you should see new version)

It depends on where your git comes from. Xcode brings a version for example, maybe that is upfront in your path.

Maybe typing

which git

will show where the old one is.


I've tried many things including all of this post's answers. Finally I was able to get brew's version of git to run instead of Xcode's by simply deleting Xcode's additional tools folder:

sudo rm -rf /Library/Developer/CommandLineTools

  • Those 'command line tools' are needed to install some Homebrew packages (when they need to be built from source). Commented Dec 29, 2021 at 22:46

You must log in to answer this question.

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