git报错_Failed to connect to github.com port 443 after xxx ms: Couldn’t connect to server
发布于: 2025-05-26 17:11:03 更新于: 2025-05-26 17:11:03

🚀 摘要

在这篇技术博客中,我们将探讨如何解决 Git 在连接 GitHub 时出现的常见错误:“Failed to connect to github.com port 443 after xxx ms: Couldn’t connect to server”。

🧠 一、问题背景分析

错误信息示例:

1
Failed to connect to github.com port 443 after xxx ms: Couldn't connect to server

这个错误通常出现在以下情况:

  • 已经开启 VPN/代理,但 Git 没有通过代理走流量
  • 系统代理设置正常,但 Git 没有感知到代理设置
  • 使用了不支持的代理协议(如 Git 默认不识别 SOCKS5);
  • 或者 科学上网工具是规则模式,Git 流量被漏掉。(鄙人就是这种)

🛠️ 二、解决步骤详解

1. ✅ 确认你可以正常上网访问 GitHub

先通过浏览器或 ping 命令确认网络畅通:

1
ping github.com

如果能 ping 通但 git clone 不行,多半是 Git 没配置代理。


2. 🔍 查找本地代理端口号

如果你使用的是 Clash、V2RayN、Surge、Shadowrocket 等代理工具,通常它监听在 127.0.0.1:7890127.0.0.1:1080

可在代理软件中查看 “HTTP 代理” 或 “SOCKS 代理” 端口:

  • Clash 默认:HTTP 端口 7890
  • V2RayN 常见:HTTP 端口 10809(用户配置)

3. ⚙️ 配置 Git 代理

若为 HTTP 代理(最常见)

1
2
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

若为 SOCKS5 代理

1
2
git config --global http.proxy socks5h://127.0.0.1:7890
git config --global https.proxy socks5h://127.0.0.1:7890

socks5h 是推荐写法,因为它支持 DNS 解析走代理。


4. 🧪 验证配置是否生效

查看当前 Git 全局代理配置:

1
git config --global -l

如果输出中包含 http.proxyhttps.proxy,说明配置成功。


5. 🔄 刷新 DNS(可选)

在 Windows 命令行中输入以下命令,清除旧的 DNS 缓存:

1
2

ipconfig /flushdns

6. 🧼 清除 Git 代理(如不再需要)

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

🧭 三、其他建议

  • 尽量将代理软件切换到全局模式测试;
  • 尝试使用镜像站(如 ghproxy.com):
1
git clone https://ghproxy.com/https://github.com/user/repo.git
  • 如果还不行,使用手机热点测试是否是局域网限制。

✅ 总结

本文介绍了当 Git 提示 无法连接到 github.com:443 时的常见原因及解决方案。核心在于:Git 本身不会自动使用系统代理,需要手动配置

上一篇
发布于: 2025-05-26 17:11:03 更新于: 2025-05-26 17:11:03