I just bought a new Mac with OS X Lion and I checked in the Terminal what version of git is installed by default. I got the answer
git --version
> git ver
It would probably be better if you added:
export PATH=/usr/local/git/bin:/usr/local/sbin:$PATH
to a file named .bashrc in your home folder. This way any other software that you might install in /usr/local/git/bin
will also be found first.
For an easy way to do this just type:
echo "export PATH=/usr/local/git/bin:/usr/local/sbin:$PATH" >> ~/.bashrc
into the Terminal and it will do it for you.
I used the following to upgrade git on mac.
hansi$ brew install git
hansi$ git --version
git version 2.19.0
hansi$ brew install git
Warning: git 2.25.1 is already installed, it's just not linked
You can use `brew link git` to link this version.
hansi$ brew link git
Linking /usr/local/Cellar/git/2.25.1...
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
hansi$ brew link --overwrite git
Linking /usr/local/Cellar/git/2.25.1... 205 symlinks created
hansi$ git --version
git version 2.25.1
The latest version was not available as a binary for mac on git-scm.com, so I installed from source. I was missing a required package for localization, and added NO_GETTEXT=true
to install without localization.
git clone https://github.com/git/git.git
cd git
make NO_GETTEXT=true
make NO_GETTEXT=true install
This installed git
under ~/bin
which I then had to add to the beginning of my PATH
variable.
The installer from the git homepage installs into /usr/local/git
by default. However, if you install XCode4, it will install a git version in /usr/bin
. To ensure you can easily upgrade from the website and use the latest git version, edit either your profile information to place /usr/local/git/bin
before /usr/bin
in the $PATH or edit /etc/paths
and insert /usr/local/git/bin
as the first entry.
It may help to someone at-least changing the order in /etc/paths worked for me.
I did it in this way:
git --version
, it should give you the latest version.I prefer not to alter the path hierarchy, but instead deal with git specifically...knowing that I'm never going to use old git to do what new git will now manage. This is a brute force solution.
NOTE: I installed XCode on Yosemite (10.10.2) clean first.
I then installed from the binary available on git-scm.com.
$ which git
/usr/bin/git
$ cd /usr/bin
$ sudo ln -sf /usr/local/git/bin/git
$ sudo ln -sf /usr/local/git/bin/git-credential-osxkeychain
$ sudo ln -sf /usr/local/git/bin/git-cvsserver
$ sudo ln -sf /usr/local/git/bin/git-receive-pack
$ sudo ln -sf /usr/local/git/bin/git-shell
$ sudo ln -sf /usr/local/git/bin/git-upload-archive
$ sudo ln -sf /usr/local/git/bin/git-upload-pack
$ ls -la
(you should see your new symlinks)