DEBUG.WIKI
阿里云;从建站到云上业务;云服务器 · 数据库 · 对象存储;查看产品 →
PanstarCloud:部署应用,接入 AI,云服务器与 AI 网关
IPPeak:从目标地区访问网页,住宅代理、SEO 监测、广告验证

解决 Git 报错 RPC failed curl 56 Recv failure 连接重置

分析 Git clone 或 fetch 大型仓库时触发 curl 56 Recv failure 的网络超时与缓冲区不足排查修复方案。

问题现象

克隆或推送体积庞大的 Git 仓库时,传输到一半中断并报错:

error: RPC failed; curl 56 Recv failure: Connection reset by peer
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

触发根因

  1. 仓库中包含大量大型二进制文件或提交历史漫长,网络传输耗时过长导致远端反向代理(如 Nginx、GitHub LB)超时切断 TCP。
  2. Git 默认的 HTTP 传输缓冲区(http.postBuffer)过小。
  3. 网络链路不稳定,存在长连接中断。

解决步骤与操作命令

步骤一:调大 Git HTTP 缓冲区大小

将缓冲区调整为 500MB 或 1GB:

git config --global http.postBuffer 524288000
git config --global https.postBuffer 524288000

步骤二:采用浅层克隆(Shallow Clone)分步拉取

避免一次性拉取整个十年历史:

# 仅克隆最近一次提交
git clone --depth 1 https://github.com/example/large-repo.git

cd large-repo

# 按需加深拉取历史
git fetch --unshallow

步骤三:改用 SSH 协议代替 HTTPS

SSH 协议通常由原生 ssh 会话保持长连接,比 HTTP/1.1 大包传输更稳定抗抖动:

git remote set-url origin git@github.com:example/large-repo.git

验证确认

重新执行代码拉取:

git pull origin main

进度条顺利接收完 100% 数据对象并完成索引构建,连接重置问题消除。