git clone使用代理加速🐌

国内访问GitHub速度较慢,克隆代码时的速度就更慢了,常常断开。因此,我们需要让我们的git走代理来加速克隆。

1
2
3
4
5
6
7
8
9
10
#只对github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

#取消代理
git config --global --unset http.https://github.com.proxy socks5://127.0.0.1:1080

#全局-推荐只代理github即可,毕竟国内的gitee还是很快的
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080

我使用的是socks5 协议,本地端口1080,因此有以上配置。

若协议、端口不同相应的更改配置命令即可。比如如果是http或https协议,本地端口是6666,则:

1
2
3
4
5

#全局
git config --global http.proxy http://127.0.0.1:6666
git config --global https.proxy https://127.0.0.1:6666

下载下载速度就快了很多很多,以前常常是几KB/s,真实受够了。

如果你没有使用自己的代理,那么你可以在浏览器中安装暴力猴或者油猴,然后安装GitHub 镜像加速下载脚本,就可以在网页中看见国内的加速链接了,复制下来去git clone就好啦。

参考

https://stackoverflow.com/questions/15227130/using-a-socks-proxy-with-git-for-the-http-transport

https://gist.github.com/laispace/666dd7b27e9116faece6