This is helpful if you've previously installed git from source on OSX, and other compilers can't find the correct path. You need to remove the current version of git, then re-install with brew.
- 
Check which git you're running:
which gitoutput should be similar to this: /usr/bin/git
 - 
Remove that git install
sudo rm -rf /usr/bin/git/ sudo rm /etc/paths.d/git sudo rm /etc/manpaths.d/git sudo pkgutil --forget --pkgs=GitOSX\.Installer\.git[A-Za-z0-9]*\.[a-z]*.pkg 
brew uninstall git
brew update
brew install git
Check which git you're now running:
which git
Should now say: /usr/local/bin/git

@akshajmody
IMPORTANT EDIT - Any solution I wrote in this comment should be ignored unless you've already done the following: restarted your terminal after running
brew install git(important!), ensuredwhich gitis returning /usr/local/bin/git and that this is what brew installed, confirmed/usr/local/bin/git --versionis displaying the new version installed via brew, and ifgit --versionis still returning the old Xcode version even after restarting your terminal then you can either use simple workarounds to add the path to the proper git install as others and myself mentioned (shown below this edit) or you can use people's solutions above to remove Xcode' git . However it's unlikely any of this is necessary with newer versions of macOS if you've restarted the terminal after installing git with homebrew. For details see @martbe's comment and my comment below it that explains where confusion can happen after installing git with homebrew alongside Xcode's git. For newer versions of macOS, the problem that myself and possibly others experienced is due to simply not restarting the terminal after runningbrew install git.See above edit before reading further.
If you do
which -a gityou'll notice there are multiple versions of git installed assuming you have one installed from XCode (or straight from git) and another that you've just installed from homebrew.e.g.,
The one in
/usr/local/bin/gitis the one from homebrew which you can confirm withls -al /usr/local/bin/gitand you'll see it's symlinked to the git binary installed in homebrew'sCellardirectory. You can alternatively confirm by passing--versionto each absolute command path to see which is which.When you run a non-absolute command like
gitit will search directories in the$PATHenvironment variable and use the first command it finds so you should runecho $PATHand ensure that/usr/local/bincomes before/usr/bin, and if it does then runninggitshould run the correct command for you. Btw, macOS sets up the$PATHvariable this way by default but if you've changed your$PATHjust ensure that/usr/local/bincomes first.If the above is true and
$PATHis correct butgit --versionis still running the/usr/bin/gitcommand then the quickest and simplest fixes are to either:alias git="/usr/local/bin/git"to~/.bash_aliases.export PATH=$PATH:/usr/local/bin/gitIf that case is happening where $PATH is correctly loading from /usr/local/bin first but
gitis still running the /usr/bin/git command, I think this may have to do with Xcode overriding things but somebody else who's more knowledgeable of Xcode can confirm this since I'm not sure. I've just seen odd things like this before, and it would explain some of these weird cases (and I know Xcode has things likexcrunto find tools). I'm just not sure. Edit - This could also be related to @martbe's point about reloading terminal, even for older versions, not sure. I'm leaving this be now lol. I've done enough damage!