0%

github 连接慢解决方案

众所周知,在中国大陆 git clone/pull/push 代码时非常慢。终端卡在那里,半天没有任何反应,不知道在干什么;好不容易连上 git 服务器,下载也是龟速。

使用命令 检测连接速度 正常情况是没什么反应的

ssh -T git@github.com

SSH 形式

对于 SSH 方式,我们可以在 ~/.ssh/config 对 SSH 设置代理,提高 git clone/pull/push 的速度。

Host github.com
User git
HostName github
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p
  • User 可以改成自己用户名 也可以不改
  • 代理端口根据自己代理改
  • 如果私钥权限有问题 需要加私钥地址 IdentityFile ~/.ssh/id_rsa

设置好执行一下
Alt text

HTTP 形式

对于 HTTP 形式的仓库地址,可以在终端里输入以下两行命令,为 Git 设置全局的 HTTP 代理,从而提高 git clone/pull/push 的速度。

git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "http://127.0.0.1:7890"

执行完后 ~/.gitconfig 会多出几行。

[http]
proxy = http://127.0.0.1:7890
[https]
proxy = http://127.0.0.1:7890