Git设置代理

有时会国内会因为github克隆速度非常慢,中途各种错误断开造成克隆项目失败,可以尝试设置代理解决,配合科学上网使用

全局代理

Bash
# HTTP代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
# socks代理
git config --global http.proxy socks5://127.0.0.1:1086
git config --global https.proxy socks5://127.0.0.1:1086

这里可以打开SS查看代理设置,查看自己的端口是否为1080,不是的改为对应的端口。

只对GitHub进行代理

如果挂了全局代理,克隆coding之类的国内仓库会变慢,所以我建议使用如下命令,只对GitHub进行代理,对国内的仓库不影响。

Bash
# HTTP代理
git config --global http.https://github.com.proxy https://127.0.0.1:1080
git config --global https.https://github.com.proxy https://127.0.0.1:1080
# socks代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1086
git config --global https.https://github.com.proxy socks5://127.0.0.1:1086

注意:以上两点都是对https协议进行代理设置,也就是仅对git clone https://www.github.com/xxxx/xxxx.git这种命令有效。对于SSH协议,也就是git clone git@github.com:xxxxxx/xxxxxx.git这种,依旧是无效的。

取消代理

Bash
git config --global --unset http.proxy
git config --global --unset https.proxy

查看已有配置

TEXT
git config --global -l