问题描述
推送代码到远程仓库时,终端显示警告信息且连接被远端强制断开(Connection reset by peer),导致推送失败。
WARNING: connection is not using a post-quantum key exchange algorithm.
...
fatal: the remote end hung up unexpectedly
这是 Git 在推送代码到远程仓库时,连接被远端强制断开导致的失败。常见原因和解决方式如下:
可能原因与处理方案
| 原因 | 说明 | 解决方式 |
|---|---|---|
| 大文件或提交过多 | 包含 PDF、图片、jar 包等大文件容易触发 GitLab 限制 | 检查是否有大文件被提交,使用 git filter-repo 或 BFG 清理历史 |
| 网络不稳定 / VPN 中断 | 内网或 VPN 环境导致连接中断 | 重试几次,或换网络 / 换 SSH 端口 |
| GitLab 服务器限制 | 服务端配置了超时或最大包大小限制 | 联系运维确认 GitLab 日志是否报错 |
| SSH 密钥或权限问题 | 权限异常时会直接断连 | 确认分支推送权限,且 SSH key 已正确配置 |
排查与修复步骤
1. 检查是否有大文件
git ls-tree -r -l dev_tianzhi | sort -k4 -n | tail -10
2. 使用 HTTPS 推送测试(排除 SSH 问题)
git remote set-url origin https://gitlab.yang.com/xxx/xxx.git
git push origin dev_tianzhi
3. 减小包大小(分批推送)
如果你本地有多个提交,可以尝试分批次推送:
git rebase -i HEAD~10 # 把多个提交合并成 1~2 个
git push origin dev_tianzhi
4. 重试推送(最简单)
git push origin dev_tianzhi


