关键词:Clash Verge、git pull 超时、GitHub 443 端口、http.proxy、https.proxy、TUN 模式
场景复现
- Windows / macOS 上启动 Clash Verge,浏览器访问 github.com 秒开。
- 打开「系统代理」或「TUN 模式」。
- 回到终端执行
结果卡住十几秒后报错:bashgit pull origin mainfatal: unable to access 'https://github.com/xxx/yyy.git/':Failed to connect to github.com port 443 after 21066 ms: Timeout
根本原因
组件 | 浏览器 | 终端 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:7890git config --global https.proxy http://127.0.0.1:7890
验证:
bash
git config --global --get http.proxy# 打印 127.0.0.1:7890 即成功
若公司仓库需要直连,可随时取消
git config --global --unset http.proxy && git config --global --unset https.proxy
③ 可选:让终端所有流量都走代理(SSH、ping 也能用)
- Clash Verge → Settings → TUN Mode → 打开「Enable TUN」
- 以管理员 (Windows) 或 root (macOS/Linux) 执行一次
bash# Windowsclash verge-service.exe enable# macOSsudo clash verge-service enable
- 重启终端,再试
git pull
/ssh git@github.com
。
常见坑 & 对应方案
现象 | 排查 & 解决 |
---|---|
端口填写正确仍超时 | 在 Clash Verge 的「Connections」标签查看有无 git 流量;若为空,说明仍直连 → 检查 TUN 模式或环境变量 |
公司 GitLab 同时走代理导致 502 | 使用「按域名分流」规则,或给 GitLab 域名设置 git config --unset |
SSH 协议仓库 git@github.com:xxx/yyy.git 超时 | SSH 不走 http.proxy ,需额外 export GIT_SSH_COMMAND="ssh -o ProxyCommand='nc -X connect -x 127.0.0.1:7890 %h %p'" 或改用 HTTPS 协议 |
一键脚本(Windows PowerShell 示例)
powershell
$port = 7890git config --global http.proxy http://127.0.0.1:$portgit config --global https.proxy http://127.0.0.1:$portWrite-Host "git 已指向 Clash Verge 端口 $port"
结论
浏览器能上网 ≠ 终端能上网。
只要记住「终端不认系统代理,只认 http(s).proxy
或 TUN 模式」,90 % 的 git 超时都能在两分钟内解决。
如果本文帮到了你,欢迎收藏 & 分享给同样被 Clash Verge + git 443 端口折磨的同事!
搭配 clash verge
powershell
git config --global http.proxy http://127.0.0.1:7897git config --global https.proxy http://127.0.0.1:7897git config --global http.sslVerify false