MirrorsProxy.Download

指南/Git 代理配置(HTTP / SOCKS)

Git 代理配置(HTTP / SOCKS)

已有代理(梯子)时不走镜像,直接给 git 配置 HTTP 或 SOCKS 代理的方法与取消命令。

什么时候用代理而不是镜像

如果你本机已有稳定的代理(Clash / v2ray 等),给 git 直接配置代理通常比镜像节点更可靠:流量只经过你自己的代理,不经第三方镜像,也不存在节点失效问题。镜像加速更适合没有代理、或服务器上只有公网 HTTP 访问的场景。不想用代理、也不想装工具?可以看 GitHub520 改 hosts。

仅对 GitHub 生效(推荐)

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

只重写 github.com 的 HTTPS 请求,公司内网 Git 服务不受影响。端口按你的代理软件调整(Clash 默认 7890)。

SOCKS5 代理

git config --global http.https://github.com.proxy socks5://127.0.0.1:7891

取消配置

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

SSH 协议怎么办?

HTTP 代理只对 https:// 远端生效。SSH 远端(git@github.com)需要在 ~/.ssh/config 里为 github.com 配置 ProxyCommand:

Host github.com
  ProxyCommand nc -X connect -x 127.0.0.1:7890 %h %p

或者干脆改用 HTTPS 远端 + 本站加速地址,省去 SSH 配置。

← 返回转换工具