Git 代理配置

使用代理的动机 内网或跨境访问 Git 仓库时,常会遇到延迟高、连接失败、TLS 握手超时等问题。通过为 Git 配置代理,可以复用团队的跳板机、单机 Clash、SS/SSR、V2Ray、企业 HTTP Proxy 等网络能力,加速 git clone、git fetch 等操作。 快速启用 HTTP/HTTPS 代理 最常见的做法是直接写入 Git 配置: # 全局配置(~/.gitconfig) git config --global http.proxy http://127.0.0.1:7890 git config --global https.proxy http://127.0.0.1:7890 如果是单个仓库,去掉 --global,在项目根目录执行即可: # 仅对当前仓库生效 git config http.proxy http://127.0.0.1:7890 git config https.proxy http://127.0.0.1:7890 可借助 git config --global -l | grep proxy 快速确认配置。 配置 SOCKS 代理 与 HTTP/HTTPS 配置类似,只是需要显式声明 socks5: # Clash / V2Ray 等提供 SOCKS 端口时 port=7891 git config --global http.proxy socks5://127.0.0.1:$port git config --global https.proxy socks5://127.0.0.1:$port 部分代理工具会同时提供 HTTP 和 SOCKS 端口,可根据需要选择。 ...

2022年4月19日 · 1 分钟 · 207 字