[Git] Error: fatal: the remote end hung up unexpectedly — How to Fix It

Summary

The Git error fatal: the remote end hung up unexpectedly usually occurs when a push or fetch operation fails mid-transfer because the connection between your system and the remote server is interrupted. This often happens with large repositories, slow networks, or when data exceeds server buffer or file size limits. The fix involves increasing Git’s HTTP buffer size, optimizing compression, and ensuring the network or server connection is stable.

Context

When Git communicates with a remote repository, it transfers data in compressed packets through HTTP or SSH. If the remote server fails to receive the full data stream, it closes the connection — producing the “remote end hung up unexpectedly” error. This can happen on push or fetch operations, especially in repositories containing large binaries, long histories, or numerous commits. Slow uploads, VPN interference, and GitHub or GitLab file size restrictions (100 MB per file on GitHub) frequently trigger this issue. CI/CD pipelines or proxies can also drop connections mid-transfer, mistaking long uploads for inactivity.

Probable Cause

  • Large data transfers exceeding Git’s default HTTP buffer size (1 MB).
  • Unstable or slow internet connections leading to dropped connections.
  • Server-side timeouts, rate limits, or overload during push/fetch operations.
  • Uploading files beyond hosting platform size limits (e.g., 100 MB on GitHub).
  • Corrupted pack files or interrupted transfers inside the repository.

Quick Fix

Follow these steps to increase stability and buffer capacity:

  1. If the error occurs during push or fetch, it likely means the server closed the connection due to data size or timeout.
  2. Check your connection stability or VPN — ensure uninterrupted upload bandwidth.
  3. Increase Git’s HTTP buffer and request limits:
git config --global http.postBuffer 524288000   # 500 MB
git config --global http.maxRequests 100
  1. Boost compression for efficiency on slow connections:
git config --global core.compression 9
  1. Confirm your repository does not exceed host file limits (e.g., 100 MB per file on GitHub).
  2. If needed, migrate large binaries to Git LFS or remove them with git filter-repo.
  3. Retry the operation:
git push origin main
  1. If the problem persists, switch to SSH for more resilient data transfer:
git remote set-url origin git@github.com:username/repo.git

Full Example

A developer tries to push a large repository to GitHub and receives:

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

They inspect the issue, noticing large objects being packed for upload. The fix is to increase buffer size and optimize compression:

git config --global http.postBuffer 524288000
git config --global core.compression 9
git push origin main

After adjusting these settings, the push completes successfully. If using HTTPS continues to fail, switching to SSH ensures a stable connection:

git remote set-url origin git@github.com:user/repo.git
git push origin main

Pitfalls & Debug

  • Symptom: “RPC failed; curl 56” after large push → Fix: Increase http.postBuffer and retry.
  • Symptom: Works on small repos only → Fix: Use Git LFS for large binaries.
  • Symptom: Fails only on VPN → Fix: Disable or reconnect to a stable network.
  • Symptom: Still failing after retry → Fix: Switch from HTTPS to SSH.
  • Symptom: Error during CI/CD pipelines → Fix: Adjust timeout or buffer settings in pipeline configuration.

Validation & Next Steps

Verify configuration and repository health:

git config --list | grep postBuffer
git fsck

Then test with a smaller push or fetch to ensure stability. If successful, retry the full operation. For persistent issues, inspect hosting limits or consider splitting the repository into smaller components.

Sources

Git documentation — git-push
Stack Overflow — “remote end hung up unexpectedly” network troubleshooting threads
GitHub Docs — Large file and size limit guidelines
Atlassian Git tutorials — handling large pushes and RPC failures

Labels: Tool/Git, OS/Windows-macOS-Linux, Topic/Network-Timeout