Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
171 views
in Technique[技术] by (71.8m points)

How to upgrade Git to latest version on macOS?

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 version 1.7.5.4

I would like to upgrade git to the latest version 1.7.8.3, so I downloaded the dmg installer "git-1.7.8.3-intel-universal-snow-leopard.dmg" and I launched it.

After the install, the Terminal still says that the version is 1.7.5.4. What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's simple if you already have Homebrew: Assuming you have homebrew installed, type the following:

brew install git

This should automatically install git and set it in your path, replacing the Apple one.

Now quit and restart your terminal.

Then check git version to confirm.

git --version

If the output of the above command shows the latest version and does not mention Apple with the version details, then you are all set.

If however you still see apple version, then type the following two lines, which will manually set our path to the local git distro instead of the Apple one.

export PATH=/usr/local/bin:$PATH
git --version

IF YOU DON'T HAVE HOMEBREW, FOLLOW THESE STEPS

Check version

$ git --version

Backup (or remove) Apple git (Optional)

$ sudo mv /usr/bin/git /usr/bin/git-apple

Install Homebrew if you didn’t have

$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Or update if you already have

$ brew update && brew upgrade

Install Git with Homebrew

$ brew install git

Symbolic link

$ brew link --force git

Quit terminal and open a new terminal, then check version.

$ git --version

You should see…

git version <latest version>

Nice! We’re safe now! And next time you can just…

$ brew update && brew upgrade


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...