GitHub仓库使用SOCKS代理

访问 GitHub 不稳定时,可以只对 GitHub 配置代理,而不是把所有 Git 请求都走代理。

只给 GitHub 配置代理

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

取消 GitHub 专用代理

git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

全局代理

如果确实希望所有仓库都走代理:

git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

取消:

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

git@github.com 场景

如果使用 SSH 协议,可以在 ~/.ssh/config 里单独配:

Host github.com
  User git
  ProxyCommand connect -S 127.0.0.1:1080 %h %p

原则

优先使用“只对 GitHub 生效”的代理配置。

这样副作用更小,也不容易影响公司内网仓库或其他 Git 服务。