This error occurs when Git's connection to a remote server is terminated before the operation completes. The most common cause is pushing or cloning large repositories over HTTP, where the default buffer size is insufficient. Increasing the http.postBuffer setting or using SSH typically resolves the issue.
The "fatal: the remote end hung up unexpectedly" error indicates that the remote Git server (like GitHub, GitLab, or Bitbucket) closed the connection before Git finished transmitting or receiving data. This typically happens during push, pull, clone, or fetch operations. The error can occur for several reasons: - **Large file transfers**: When pushing commits that include large files or many changes, the HTTP POST request may exceed server limits or timeout thresholds - **Network instability**: Poor network connectivity, high latency, or intermittent connections can cause the server to drop the connection - **Server-side limits**: The remote repository host may have size limits, timeout settings, or rate limits that terminate long-running requests - **Proxy or firewall interference**: Corporate networks, VPNs, or security software may interrupt connections that take too long or exceed size thresholds The error message itself doesn't indicate the root cause, so troubleshooting involves trying different configuration options and connection methods.
The most common fix is to increase Git's HTTP buffer, which defaults to only 1 MB:
# Set buffer to 500 MB (recommended starting point)
git config --global http.postBuffer 524288000For very large repositories, you may need even more:
# Set buffer to 1 GB
git config --global http.postBuffer 1048576000To set this only for the current repository (not globally):
git config http.postBuffer 524288000After changing this setting, retry your git operation.
If you're on a slow or unstable network, adjust timeout settings:
# Disable low speed limit (prevents timeout on slow connections)
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999These settings tell Git not to abort the connection even if the transfer speed drops very low.
Compression adds CPU overhead and can cause issues with very large transfers:
# Disable compression
git config --global core.compression 0
# Optionally limit pack window size
git config --global pack.window 1This trades bandwidth for reliability - useful when the issue is timeout-related rather than bandwidth-related.
SSH connections are often more reliable for large transfers and avoid HTTP-related buffer issues:
Check your current remote URL:
git remote -vChange from HTTPS to SSH:
# GitHub
git remote set-url origin [email protected]:username/repository.git
# GitLab
git remote set-url origin [email protected]:username/repository.git
# Bitbucket
git remote set-url origin [email protected]:username/repository.gitEnsure your SSH key is set up:
# Check if you have an SSH key
ls -la ~/.ssh/
# Test SSH connection to GitHub
ssh -T [email protected]
# Test SSH connection to GitLab
ssh -T [email protected]If you don't have an SSH key configured, see your hosting provider's documentation for SSH key setup.
If you have many commits or large changes, push them incrementally:
# Push commits one at a time
git log --oneline origin/main..HEAD | tail -1
# Get the oldest commit hash, then:
git push origin <commit-hash>:main
# Repeat for remaining commitsOr use a script to push incrementally:
#!/bin/bash
# Push commits in batches of 10
for commit in $(git rev-list --reverse origin/main..HEAD | awk 'NR % 10 == 0'); do
git push origin $commit:main
done
git push origin HEAD:mainThis approach is especially useful when you have a backlog of many commits to push.
When cloning large repositories, use a shallow clone to reduce data transfer:
# Clone only the last 1 commit
git clone --depth 1 https://github.com/username/repository.git
# Clone only the last 10 commits
git clone --depth 10 https://github.com/username/repository.git
# Later, if you need full history:
git fetch --unshallowFor very large repositories, you can also clone only a specific branch:
git clone --depth 1 --branch main --single-branch https://github.com/username/repository.gitLarge files are a common cause of this error. Find them before pushing:
# Find large files in your working directory
find . -type f -size +50M -not -path './.git/*'
# Find large files in git history
git rev-list --objects --all | \
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | \
awk '/^blob/ {print substr($0,6)}' | \
sort -rnk2 | \
head -20If you find large files that shouldn't be in the repository:
- Add them to .gitignore
- Consider using Git LFS (Large File Storage) for files that need versioning
- Remove them from history using git filter-repo if already committed
Get verbose output to understand exactly where the failure occurs:
On Linux/macOS:
export GIT_TRACE_PACKET=1
export GIT_TRACE=1
export GIT_CURL_VERBOSE=1
git pushOn Windows (PowerShell):
$env:GIT_TRACE_PACKET=1
$env:GIT_TRACE=1
$env:GIT_CURL_VERBOSE=1
git pushThis will show detailed information about the HTTP requests and responses, helping identify whether the issue is:
- Connection timeout
- Server rejection (look for HTTP 413 or 408 status codes)
- SSL/TLS issues
- Authentication problems
Corporate networks often have proxies or firewalls that interfere with large transfers:
Check current proxy settings:
git config --global --get http.proxy
git config --global --get https.proxyIf you need to use a proxy:
git config --global http.proxy http://proxy.example.com:8080
git config --global https.proxy http://proxy.example.com:8080If proxy is causing issues, try without it (if network allows):
git config --global --unset http.proxy
git config --global --unset https.proxyFor VPN issues, try:
- Temporarily disconnecting from VPN
- Using SSH instead of HTTPS
- Contacting your IT department about git traffic whitelisting
If other solutions don't work, the issue may be network-specific:
- Switch from WiFi to mobile data (or vice versa) to test
- Try a different WiFi network if available
- Restart your router to get a fresh connection
- Reinstall network drivers on Windows if issue persists across networks
If the operation works on a different network, the issue is likely:
- ISP-level traffic shaping
- Network equipment limitations
- Firewall or security software on the original network
In CI/CD environments, this may indicate network issues with the build runner.
Understanding Git's Smart HTTP Protocol:
Git uses "Smart HTTP" for transfers over HTTP/HTTPS. When pushing data larger than the http.postBuffer size (default 1 MB), Git switches to HTTP/1.1 chunked transfer encoding. Some servers and proxies don't handle chunked encoding well, causing connection drops.
Server-Side Configuration:
If you control the Git server or reverse proxy, check these settings:
nginx:
# Increase max body size (default is 1MB)
client_max_body_size 500M;
# Increase timeouts
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;Apache:
# Increase timeout (in seconds)
Timeout 600
ProxyTimeout 600Git Pack Internals:
When you push, Git creates a "pack" of objects. The pack size depends on:
- Number of new objects (commits, trees, blobs)
- Compression settings
- Delta encoding effectiveness
For extremely large pushes:
# Create smaller packs
git config pack.packSizeLimit 100m
# Reduce memory usage during packing
git config pack.threads 1
git config pack.windowMemory 100mGit LFS for Large Files:
If you regularly work with large files, consider Git LFS:
# Install Git LFS
git lfs install
# Track large file types
git lfs track "*.psd"
git lfs track "*.zip"
git lfs track "*.mp4"
# Add the .gitattributes file
git add .gitattributes
git commit -m "Configure Git LFS"SSH Buffer Configuration:
For SSH connections, you can similarly increase buffer sizes:
git config --global ssh.postBuffer 524288000Curl Error Codes:
The error often appears with "RPC failed; curl XX" where XX indicates:
- curl 18: Transfer closed with outstanding read data remaining
- curl 56: Failure with receiving network data (CURLE_RECV_ERROR)
- curl 55: Failed sending network data
- curl 7: Failed to connect to host
Debugging Network Issues:
For persistent issues, capture a network trace:
# On Linux
tcpdump -i any -w git-push.pcap port 443 &
git push
kill %1
# Analyze with WiresharkCI/CD Specific Considerations:
In CI/CD pipelines, this error often indicates:
- Insufficient memory for the git operation
- Network throttling on shared runners
- Docker networking issues when using containers
Consider using git clone --depth for CI builds to reduce data transfer.
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git