MacOs 升级 Git 到最新版本

1. 检查当前 git 版本

$ git --version

2. 备份 git

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

3. 如果没安装 homebrew 则安装

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

切换国内镜像加速访问

$ cd "$(brew --repo)"
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
$ git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

$ brew update

# 如果使用 iterm2,将下面的 `.bash_profile` 替换为 `.zshrc`
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile  
$ source ~/.bash_profile

4. 已安装 homebrew 则更新

$ brew update && brew upgrade

5. 使用 homebrew 安装 git

$ brew install git

6. 查看更新后的版本

$ git --version

7. 下次更新 git 只需

$ brew update && brew upgrade
参考来源

How to upgrade Git (Mac OSX)

本作品采用《CC 协议》,转载必须注明作者和本文链接
Allen
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!