踩坑日记:为什么Git 突然 Push 不上去了

今天在开发的时候遇到一个很离谱的问题,git push 明明昨天还好好的,结果今天突然完全推不上去。

报错信息如下:

vbnet 复制代码
ERROR: no healthy upstream
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

或者是

vbnet 复制代码
ERROR: upstream connect error or disconnect/reset before headers.
remote connection failure, transport failure reason: delayed connect error: Connection refused
fatal: Could not read from remote repository.

一开始我以为是 GitHub 挂了,或者我 SSH key 失效了。结果一切正常:

vbnet 复制代码
ssh -T git@github.com

Hi shenlu89! You've successfully authenticated, but GitHub does not provide shell access.

我又查了一下远端Git仓库的URL是否正确:

scss 复制代码
git remote -v 
origin  git@github.com:shenlu89/docs.git (fetch)
origin  git@github.com:shenlu89/docs.git (push)

SSH 连接没有问题

  • 仓库地址没错
  • SSH 授权正常
  • git remote -v 正常

那问题从哪里来?

正常来说,使用 SSH 方式 push,那只要 ssh -T 可用,push 一定可用,但我这里:

java 复制代码
ssh -T git@github.com   // 正常
git push                // 失败

这说明 push 底层不是简单的 SSH 问题,而是 连接被代理或网络干扰了。

继续排查 macOS 系统代理:

arduino 复制代码
networksetup -getwebproxy "Wi-Fi"
networksetup -getsocksfirewallproxy "Wi-Fi"

结果是:

yaml 复制代码
Enabled: Yes
Server: 127.0.0.1
Port: 7890

也就是说,macOS 系统级 HTTP/HTTPS/SOCKS 都指向了 127.0.0.1:7890。

这就导致所有 Git 连接走系统代理,系统代理为空,请求被直接拒绝,Git push 报 connection refused

这就是为什么 SSH 测试能连,但 git push 反而失败。

因为 SSH 测试命令不走系统代理,而 Git push 走了。

直接关掉 macOS 的代理即可:

vbnet 复制代码
networksetup -setwebproxystate "Wi-Fi" off
networksetup -setsecurewebproxystate "Wi-Fi" off
networksetup -setsocksfirewallproxystate "Wi-Fi" off

然后:

perl 复制代码
git push

瞬间恢复正常。

还有一种方法,就是将 GitHub SSH 改用 443 端口,为了兼容各种奇怪网络环境(公司、学校、酒店 WiFi 等),我顺手也把 GitHub SSH 通道改到了 443 端口,编辑 ~/.ssh/config:

bash 复制代码
Host github.com
    HostName ssh.github.com
    Port 443
    User git
    IdentityFile ~/.ssh/id_ed25519
    IdentitiesOnly yes

443 端口一般不会被封,也不受代理影响,比 22 端口稳定太多。

这样问题就成功解决了。

相关推荐
2分钟速写快排4 小时前
孔乙己的茴字有多少种写法?|AI 对话实时通信的三种实现
前端·javascript·github
wangruofeng8 小时前
同一行代码,百种渲染:Asuka、React Native 与 Flutter 跨平台渲染机制深度拆解
前端·github
杨凯凡9 小时前
IT日报|2026-11-13:GitHub 大规模凭据攻击、Signal 形式化验证、Claude 新模型与 AI 安全诉讼
人工智能·安全·github
liuzheng662113 小时前
我给 Agent 测试注入了 72 种谎话,它抓住了 44 种
github
feasibility.19 小时前
一物降一物?AI逆向没有终局:REA拆App,BLA设套,LASIK清场
人工智能·爬虫·github·逆向·skill·rea
wno70420 小时前
常用的Git命令清单
大数据·git·elasticsearch
真上帝的左手1 天前
3. 代码管理-Git-进阶
git·源代码管理
程序开发阿元1 天前
密码不进工具:一个独立开发者的服务器凭据管理办法
linux·ssh
真好啊又活了一天2 天前
服务器和虚机配置IPV6
运维·服务器·github
Cosolar2 天前
极简简历:开源免费,希望帮助到更多求职者
开源·github·敏捷开发