ILLASTATION

git_clone加速方法整理

之前有兄弟反应git clone时卡在一个地方卡着, 其实这种状况并不稀奇, 网上有许多git clone加速的办法, 整理一下:

  1. 使用github的镜像站:

    使用方法也很简单, 直接将github.com替换掉即可: 教程,

    注: 这种方法只能用于https协议, 不能用git协议, https克隆后怎样修改才能面密登录? 参考: Git之SSH与HTTPS免密码配置 ,或者直接将.git/config中url改成git协议

  2. 使用代理

    可能服务器上可能不会装代理, 拷到本地再复制到服务器上也快不少(服务器不会限制上行速度)

  3. 对于github这种被”矮墙”的, 更改hosts是常见手段, hosts加上这里的内容

    怎么修改hosts? 不同系统文件位置不同, 具体请百度

  4. 使用gitee从github导入后再clone gitee, 如果不需要远程提交到github是没问题的, 但如果要PR, 没试过是否可行

  5. nginx反向代理: 教程

详细说明

配置git代理

https协议

端口自行更改

走 HTTP 代理
1
2
git config --global http.proxy "http://127.0.0.1:8080"
git config --global https.proxy "http://127.0.0.1:8080"
走 socks5 代理(如 Shadowsocks)
1
2
git config --global http.proxy "socks5://127.0.0.1:1080"
git config --global https.proxy "socks5://127.0.0.1:1080"
取消设置
1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

git协议

windows系统下 C:\Users\用户名\.ssh\config

linux系统下~/.ssh/config

添加如下几行:

端口自行更改

1
2
3
4
5
6
7
Host github.com
HostName github.com
User git
# 走 HTTP 代理
ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
# 走 socks5 代理
ProxyCommand nc -v -x 127.0.0.1:1080 %h %p