tldr;
解决方法(HTTP/HTTPS 方式克隆仓库):
bashgit config --global http.proxy http://127.0.0.1:7897git config --global https.proxy http://127.0.0.1:7897
如果要取消设置:
git config --global --unset http.proxy && git config --global --unset https.proxy
场景复现
Windows / macOS 上启动 Clash Verge,并打开「系统代理」或「TUN 模式」浏览器访问 github.com 秒开。 但在终端执行 git pull origin main 却结果卡住十几秒后报错:
fatal: unable to access 'https://github.com/xxx/yyy.git/':Failed to connect to github.com port 443 after 21066 ms: Timeout
问题原因
在 Clash Verge 的代理环境中,浏览器能够正常访问 GitHub,是因为浏览器会自动读取系统的代理设置,并将请求发送到 Clash Verge 的本地代理端口(如 7890)。Clash Verge 作为代理服务器,接收这些请求,然后将它们转发到目标服务器。
而在终端执行 Git 操作时,Git 并不会自动继承系统代理的设置。它依赖于自己的配置来确定是否使用代理以及如何使用代理。然而,Git 默认情况下并不使用系统代理,而是直接尝试连接到 GitHub 的 443 端口。由于该端口可能受到网络策略的限制,导致连接被拒绝或超时。
| 组件 | 浏览器 | 终端 git |
|---|---|---|
| 代理读取方式 | 直接读取系统代理设置 (WPAD/WinHTTP) | 只认 http(s)_proxy 环境变量或 git config 的 http(s).proxy |
| 默认端口 | 与 Clash Verge 一致 | 未配置则直连,443 被墙即超时 |
| 额外影响 | — | 如果开了 TUN 但路由表异常,也会绕过虚拟网卡 |
一句话:浏览器走了 Clash Verge,终端 git 还在直连。
三步解决
① 查看 Clash Verge 本地端口
打开 Clash Verge → Settings → General
记录「Mixed Port」或「HTTP Port」;多数情况下是 7890 或 7897。
下文以 7890 为例。
② 给 git 指定代理
bash# HTTP/HTTPS 方式克隆仓库git config --global http.proxy http://127.0.0.1:7897git config --global https.proxy http://127.0.0.1:7897
验证:
