Actually, there are two questions.
One is how to install a higher version of git?
You can use git-osx-installer or brew.
It is recommended to install with brew: brew install git
Another one is how to make the newly installed git overwrite the old git?
It is recommended to modify ~/.bash_profile and add the following content: export PATH=/usr/local/bin:/usr/local/sbin:${PATH}
This allows bash to search for instructions under /usr/local first, and will not overwrite old files, which is safer.
I also used git installed with brew. When I first used OSX Lion, I always used git installed with brew. Later, after reinstalling OSX Mountain Lion, I found that the default git is the one that comes with the system and the version is relatively old. I I am another patient with obsessive-compulsive disorder about upgrading. I have also considered changing the path like @Hoho. However, due to some reasons that I am not sure about (some problems I encountered when I first started using Mac), I am worried that putting /usr/local/bin may be in front. It will affect some things that I don't pay attention to. Later, I simply put it in .zshrc (I use zsh)
alias git="/usr/local/bin/git"
Everything is currently running normally and does not affect anything else. No side effects
I used this method http://apple.stackexchange.com/a/3913...
Changed.bash_profile这个文件.然后让/usr/local/bin这个文件夹出现在/usr/bin之前. 虽然我是从git的官方网站上下载的安装dmg文件. 但是却不能安装. 需要改路径才行. 我也知道可以用brew的方式安装. 但是个人感觉那个有些时候不是最新的发行版本. 而且老是从SourceForgeWhen downloading from third-party websites, the speed is not very fast. (Maybe it’s because of GFW)
It seems that this thing is caused by Apple’s own Xcode. http://apple.stackexchange.com/q/2012...
I installed xocde first, so it comes with a git version of 1.8.5.
Then I want to install a new version of git instead of 1.8.5. What I do is:
Install brew first, -> brew install git -> brew doctor
Note that brew doctor will automatically detect some settings and prompt you to modify them, such as making the brew download command at the front of PATH.
In this way, it can be replaced with a new version in git and can be updated through brew.
1 It is recommended to use homebrew to install components under mac system. 2 Install homebrew terminal: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) 3 Upgrade homebrew to the latest version
brew update
4 Use the latest version of homebrew to check which software needs to be updated. (Take git as an example)
Actually, there are two questions.
One is how to install a higher version of git?
You can use git-osx-installer or brew.
It is recommended to install with brew:
brew install git
Another one is how to make the newly installed git overwrite the old git?
It is recommended to modify ~/.bash_profile and add the following content:
export PATH=/usr/local/bin:/usr/local/sbin:${PATH}
This allows bash to search for instructions under /usr/local first, and will not overwrite old files, which is safer.
I also updated my git. It is very convenient to update with homebrew.
If you have homebrew installed:
My approach is:
After update
The advantage is that other components of git are also up to date. And the old git will not appear during git completion
I also used git installed with brew. When I first used OSX Lion, I always used git installed with brew. Later, after reinstalling OSX Mountain Lion, I found that the default git is the one that comes with the system and the version is relatively old. I I am another patient with obsessive-compulsive disorder about upgrading. I have also considered changing the path like @Hoho. However, due to some reasons that I am not sure about (some problems I encountered when I first started using Mac), I am worried that putting /usr/local/bin may be in front. It will affect some things that I don't pay attention to. Later, I simply put it in .zshrc (I use zsh)
Everything is currently running normally and does not affect anything else. No side effects
I used this method http://apple.stackexchange.com/a/3913...
It seems that this thing is caused by Apple’s own Xcode.
http://apple.stackexchange.com/q/2012...
I installed xocde first, so it comes with a git version of 1.8.5.
Then I want to install a new version of git instead of 1.8.5. What I do is:
Install brew first, -> brew install git -> brew doctor
Note that brew doctor will automatically detect some settings and prompt you to modify them, such as making the brew download command at the front of PATH.
In this way, it can be replaced with a new version in git and can be updated through brew.
brew install git
...
➜ meetup git:(master) git --version
git version 1.9.3 (Apple Git-50) //旧版本
➜ meetup git:(master) which git
/usr/bin/git
➜ meetup git:(master) sudo mv /usr/bin/git /usr/bin/git-1.9.3
Password:
➜ meetup git:(master) which git
/usr/local/bin/git
➜ meetup git:(master) git --version
git version 2.2.1
// 搞定
1 It is recommended to use homebrew to install components under mac system.
2 Install homebrew terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)
3 Upgrade homebrew to the latest version
4 Use the latest version of homebrew to check which software needs to be updated. (Take git as an example)
5 If git needs to be updated: