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?

  • 2
    You have a couple good answers - so I wanted to comment on the question. Are you looking for explicit instructions to install git from source from homebrew or a GUI client or just confirmation that OS X bundles several versions of git with the core OS? opensource.apple.com/source/Git (FWIW - The newest git I've seen Apple bundle to date is which comes from Git-37) – bmike Jun 3 '13 at 13:00

14 Answers 14


Thanks everyone for helpful answers. In my case adding

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

in ~/.bash_profile followed by

source ~/.bash_profile

solved the problem for my user.

| improve this answer | |
  • 22
    If you want the change persistent across users, you can move /usr/local/bin above /usr/bin in /etc/paths. – kevin Nov 12 '13 at 5:08
  • 3
    This is the solution proposed by Homebrew itself when running brew doctor to diagnose the issue – VoxPelli Dec 4 '13 at 14:22
  • 1
    this answer should be updated with the KevinT proposed solution of defining /etc/paths. Defining only the "export" may not be enough, if /usr/bin has "precedence" over /usr/local/bin (from brew)... – emgsilva Dec 9 '13 at 11:43
  • 9
    Remember to restart terminal! Didn't occur to me until i saw Juan Diego Gonzales's comment below – Souleiman Jun 30 '15 at 14:33
  • 2
    @Souleiman: Restarting isn't necessary. source ~/.bash_profile will re-read that. Restarting is just probably faster/easier. :) – user2702 Oct 5 '15 at 23:12

Status 2020

All the tricks mentioned here in several answers are not necessary anymore on macOS Sierra, Mojave & Catalina 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.

| improve this answer | |
  • 32
    I think this is right, but you need to open a new terminal or the change isn't picked up – robjwilkins Jun 28 '17 at 8:49
  • 1
    That wouldn‘t be related to the most recent Homebrew version but to the fact that /usr/local/bin is in the default path on a clean macOS install. Which I can‘t verify right now but assume you did. – nohillside Jan 14 at 6:19
  • I wish we could highlight @robjwilkins comment. I've been using bash / zsh terminals for many many years but I still managed to forget to reopen the terminal, so I was wasting time troubleshooting an issue that didn't exist until I saw his comment. – the-nick-wilson Sep 25 at 21:39
  • 1
    @the-nick-wilson I had already added a corresponding line to the posting after the comment of Rob. Have now added yet another sentence to hammer that nail even deeper. :D – Jpsy Sep 26 at 3:23
  • Haha, thank you @Jpsy. – the-nick-wilson Sep 28 at 18:17

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

| improve this answer | |
  • 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 Jun 17 '15 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 Jun 30 '15 at 14:33
  • 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 Dec 22 '15 at 18:28
  • 6
    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 – Vladislav Rastrusny Jun 19 '17 at 13:45
  • 1
    Just use brew doctor. In 2020, it recommended brew link —overwrite git – User that is not a user Jan 18 at 16:03

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.

| improve this answer | |
  • 1
    How does this differ from the accepted answer? – mmmmmm Jan 21 '14 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). – Juan Diego Gonzales Jan 22 '14 at 0:51
  • You do that one liner when you install Homebrew – mmmmmm Jan 22 '14 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 Jan 28 '15 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 – kstratis Dec 7 '15 at 11:24

I tried this and it works for me.

brew link --overwrite git
| improve this answer | |
  • Worked for me on Mojave (10.14.4) – peppered Apr 1 '19 at 11:14

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.

| improve this answer | |
  • Is this 100% safe? Will it break anything mac related? – Levani Jun 3 '13 at 15:58
  • If you follow the steps outlined, the solution won't break anything pre-installed since those git executables are not deleted. This is why at step 2 you should rename your original /usr/bin/git for e.g. as /usr/bin/git.BACKUP – Global nomad Jun 3 '13 at 16:09
  • 10
    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 Jun 3 '13 at 17:03
  • Thanks @MattDMo, that seem to be the best approach in this case. – Levani Jun 5 '13 at 13:25

Install git with brew, the run this.

brew link --force git

Close and reopen terminal to run which git.

| improve this answer | |
  • 1
    How does that change the default path? – mmmmmm Apr 15 '17 at 6:46
  • This worked for me to override xcode's git. – surjikal Feb 15 '18 at 23:59
  • I got an error when running this but brew link --overwrite git worked – wickdninja Feb 20 '19 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.

| improve this answer | |
  • 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 Jun 3 '13 at 14:16
  • @Mark you have a point. But I do not believe you will get trouble if you change only git in /usr/bin. For me it is working for several month. – Pfitz Jun 3 '13 at 14:18
  • I would agree that normally changing things in /usr/bin is bad news, but I can't recall OS X actually using git, so the harm there might be minuscule and only relate to a "clean" system that matches the receipts. The harm would be an update to OS X might replace the new git with an older version, hence the normal practice to locate a new binary outside the system path location. – bmike Jun 3 '13 at 16:13
  • 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 Jun 3 '13 at 17:05

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)
| improve this answer | |

Do a simple alias to avoid changing path:

alias git=/usr/local/bin/git
| improve this answer | |

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

| improve this answer | |

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.

| improve this answer | |
  • it's in /usr/bin/git... – Levani Jun 3 '13 at 12:12
  • 2
    That looks like two installations. I think the normal (downloadable) git version goes to /usr/local/git/... It's then a question of adding that to the path or removing the other (or both) – Nicholaz Jun 3 '13 at 12:17

Simplest way:

$ git --version
git version 2.24.3 (Apple Git-128)

$ which git

We want it to be simple to maintain and not be dependent on Apple's version, so:

$ brew install git

$ git --version
git version 2.24.3 (Apple Git-128)

$ which git

At this point, not need extra work, simply:

Terminal > ⌘Q
Spotlight > Terminal > Hit "Enter"
$ git --version
git version 2.29.2
$ which git

And you are good to go.

As you can see, this issue was related to the current Terminal session. As soon as you completely close the Terminal session and open a new one, it's fixed.

| improve this answer | |

To upgrade anything using Homebrew on OSX which involves compilation using gcc, make sure you have the updated Command Line Tools from Xcode—yeah, I know, it sucks having to hide a system-wide tool in the preferences of an app.


  1. Go to Xcode.app —> Preferences —> Downloads
  2. Update (or install) Command Line Tools
  3. Run brew doctor and fix all other hinderances
  4. Run brew upgrade to upgrade all packages at once
| improve this answer | |

You must log in to answer this question.

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