美兰十三的想疗院


一个不务正业的前端狗,爱纹身、玩乐队、哥金党、专门写Bug~


MacOS 升级git

MacOS 升级git

系统自带的git 版本一般会比较的老
比如我的macbook pro macOS Mojave 10.14.5 的git版本是 2.12
于是在日常开发中会遇到一个问题

想用 husky 等 工具控制 git hook 来控制不合规代码的 commit 就会报错,无法顺利执行 pre-commit 操作

那么保持git版本的更新就很必要了。

mac上最方便的 大概就是 HOMEBREW 了
所以我们就用 HOMEBREW 来安装可控的git吧。

但是 HOMEBREW 的标准镜像在国外,所以。。。连接很有问题。。。
所以我们先切换到国内镜像吧!

第一步安装(已安装的就忽略直接下一步)

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

第二步 切换国内镜像(清华大学的镜像站还是很给力的)

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

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

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

$ brew update

# 如果使用 iterm2 在 `.zshrc` 中 加入 `source ~/.bash_profile`
$ echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile

$ source ~/.bash_profile

第三步 更新 HOMEBREW

$ brew update && brew upgrade

第四步 安装git

$ brew install git

完美!

之后就能直接用 brew link git 控制 git的版本了

当然 以上并没有结束

你会发现你的 git版本还是老的。。。
这时候呢 我们打开 ~/.bash_profile
加入以下代码(一定要加在尽量靠下的地方 所有的 export 都是从上往下读取的,所以 越往下 权重越高)

# Add HOMEBREW tools to $PATH (/usr/local/bin)
export PATH=$(brew --prefix)/bin:$PATH

好了 我们重启下 Terminal 或者 iTerm2 再看一下 git --version

现在我们的 git 就变成 brew 安装的最新版的 git了~

精彩!

建议打赏金额1-10元

支付宝打赏

微信打赏

最近的文章

npm i -g 全局安装 sudo 消除

2020-07-06更新 https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-g…

npm, sudo, permission denied 继续阅读
更早的文章

诺锞前端开发规范

前端开发规范 v1.2.3 Copyright (c) by PT IHU URSA Team - Luna Zhou 命名规范 前言 规范等级 【必须】 :绝对,严格…

前端规范, URSA Team 继续阅读
comments powered by Disqus
沪ICP备15043964号-3