git push: fatal: 远程端意外挂断 到 github.com 的连接被远程主机关闭

git push: fatal: the remote end hung up unexpectedly Connection to github.com closed by remote host

我正在使用 ssh 和 RSA 密钥访问 github,但是当我将文件推送到存储库时它不起作用。

ykhan21@LENOVO-LEGION:~/repos/homework-1-ykhan21$ git push
Enumerating objects: 6, done.
Counting objects: 100% (6/6), done.
Delta compression using up to 12 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 2.79 KiB | 2.79 MiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
Connection to github.com closed by remote host.

我该如何解决这个问题?

这个问题可以作为参考:Git, fatal: The remote end hung up unexpectedly

  • 一些用户遇到这个问题是由于缓冲区设置造成的:例如git config ssh.postBuffer 524288000
  • 您可能在 repo 中错误配置了您的远程(您可以使用 git remote -v 进行检查)或 ssh 密钥对
  • 在其他情况下,运行 垃圾收集器解决了问题 (git gc)
  • 如果您以 root (sudo) 身份创建存储库并且为您的用户安装了 git,您可能缺少写入权限

我发现这个错误通常发生在你的文件太大的时候。但我的文件没有,我能够推动我所有的其他项目。重新克隆到一个单独的目录有帮助,但它没有解决原来的问题。

我在尝试推送提交时也遇到了这个问题,但我能够从我的其他分支推送和拉取。当我再次尝试推送有问题的分支时,它成功了。