一、核心原因分析
代理配置异常:本地开启了代理(如梯子、公司代理),但 Git 未配置代理,或代理配置错误;DNS 解析失败:本地 DNS 缓存过期 / 污染,导致无法解析 github.com 域名;网络 / 防火墙限制:本地防火墙、杀毒软件、公司 / 校园网络屏蔽了 443 端口;GitHub 服务器临时故障:极少情况,可通过 GitHub Status 验证;HTTPS 协议限制:部分网络环境对 HTTPS 协议的 443 端口做了拦截。
二、解决方案
方案 1:清除 / 重置 Git 代理配置(最常见解决方式)
很多开发者开启了代理但未同步配置到 Git,或代理配置错误,是导致 443 报错的首要原因。
步骤 1:查看当前 Git 代理配置
# 查看 Git 全局代理配置
git config --global --get http.proxy
git config --global --get https.proxy
步骤 2:清除错误的代理配置
如果代理配置错误 / 不需要代理,直接清除:
# 清除 http/https 代理
git config --global --unset http.proxy
git config --global --unset https.proxy
步骤 3:配置 Git 全局代理
# 方案 1:SOCKS5 代理(推荐,兼容性更好)
git config --global http.https://github.com.proxy socks5://127.0.0.1:7891
git config --global https.https://github.com.proxy socks5://127.0.0.1:7891
# 方案 2:HTTP 代理(若 SOCKS5 不行)
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy http://127.0.0.1:7890
方案 2:切换 SSH 协议
GitHub 的 HTTPS 协议易被网络拦截,SSH 协议更稳定,且无需频繁验证身份。
步骤 1:生成 / 配置 SSH 密钥(首次使用需操作)
- 打开终端,执行密钥生成命令(替换为你的 GitHub/Gitee 邮箱):
# 推荐 ED25519 算法(更安全)
ssh-keygen -t ed25519 -C "[email protected]"
# 若系统不支持 ED25519,改用 RSA
ssh-keygen -t rsa -b 4096 -C "[email protected]"
- 执行后全程按回车(默认路径、无密码),密钥会生成在:
- Windows:
C:\Users\你的用户名\.ssh\id_ed25519.pub(或 id_rsa.pub) - Mac/Linux:
~/.ssh/id_ed25519.pub(或 id_rsa.pub)
- Windows:
-
复制公钥内容:
- Windows(Git Bash):
cat ~/.ssh/id_ed25519.pub,复制输出的全部内容; - Mac/Linux:(直接复制到剪贴板)。
- Windows(Git Bash):

