Clash Verge 代理后浏览器能上 GitHub,命令行 git pull 却超时解决方法

Clash Verge 代理后浏览器能上 GitHub,命令行 git pull 却超时解决方法

更新于 2025-08-30
1956

关键词:Clash Verge、git pull 超时、GitHub 443 端口、http.proxy、https.proxy、TUN 模式

场景复现

  1. Windows / macOS 上启动 Clash Verge,浏览器访问 github.com 秒开。
  2. 打开「系统代理」或「TUN 模式」。
  3. 回到终端执行
    bash
    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

根本原因

组件浏览器终端 git
代理读取方式直接读取系统代理设置 (WPAD/WinHTTP)只认 http(s)_proxy 环境变量或 git confighttp(s).proxy
默认端口与 Clash Verge 一致未配置则直连,443 被墙即超时
额外影响如果开了 TUN 但路由表异常,也会绕过虚拟网卡

一句话:浏览器走了 Clash Verge,终端 git 还在直连


三步解决

① 查看 Clash Verge 本地端口

打开 Clash Verge → Settings → General
记录「Mixed Port」或「HTTP Port」;多数情况下是 78907897
下文以 7890 为例。

② 给 git 指定代理

bash
# HTTP/HTTPS 方式克隆仓库
git config --global http.proxy http://127.0.0.1:7890
git 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 也能用)

  1. Clash Verge → Settings → TUN Mode → 打开「Enable TUN」
  2. 以管理员 (Windows) 或 root (macOS/Linux) 执行一次
    bash
    # Windows
    clash verge-service.exe enable
    # macOS
    sudo clash verge-service enable
  3. 重启终端,再试 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 = 7890
git config --global http.proxy http://127.0.0.1:$port
git config --global https.proxy http://127.0.0.1:$port
Write-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:7897
git config --global https.proxy http://127.0.0.1:7897
git config --global http.sslVerify false