git clone 时速度过慢的解决办法

  从 github 上 clone repository 时速度过慢,甚至达到 2.00 KiB/s 夸张的速度,解决方式是科学上网,似乎开启 shadowsocks 后在系统设置全局代理并不起作用,如果要 git 走代理需要在 git config 中设置才可以.

  设置科学上网当然要开启 shadowsocks, 设置本机地址 127.0.0.1, 本机端口 1080.

  git 设置代理可以设置全局代理即所有 host 都走代理,也可以针对单独一个 host 设置代理即只 clone 此 host 上的 repository 时才走代理.由于本人的 VPS 在美国,所以只对 github 设置代理.

  shadowsocks 暴露的协议为 socks5,所以设置时的代理前缀为 socks5.

具体命令

1
2
3
4
5
6
7
# 设置 http, https 的代理
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

# 要取消设置的http, https 代理,命令如下
git config --global --unset http.proxy
git config --global --unset https.proxy