Apple - How to use the Homebrew installed git on Mac?

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.


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.


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

Tags:

Git

Homebrew