Git HTTP 400 Error: Solutions for Large Repository Push Failures
When pushing large repositories to remote Git servers, you may encounter the frustrating "RPC failed; HTTP 400" error followed by "The remote end hung up unexpectedly." This common issue occurs when Git's HTTP transport encounters limitations when handling large amounts of data.
Problem Overview
The error typically appears during the final stages of a push operation:
Counting objects: 19815, done.
Compressing objects: 100% (5264/5264), done.
Writing objects: 100% (19815/19815), 44.91 MiB | 134.87 MiB/s, done.
Total 19815 (delta 14641), reused 19405 (delta 14283)
error: RPC failed; HTTP 400 curl 22 The requested URL returned error: 400 Bad Request
fatal: The remote end hung up unexpectedly
fatal: The remote end hung up unexpectedly
Everything up-to-date
This error can stem from several causes:
- HTTP buffer size limitations
- Large commits or files
- Network configuration issues
- Server-side restrictions
Primary Solutions
1. Increase HTTP Post Buffer Size
The most common solution is to increase Git's HTTP post buffer, which controls the maximum size of data that can be sent in a single request:
git config http.postBuffer 524288000
This sets the buffer to 500MB (524,288,000 bytes). For a global configuration that applies to all repositories:
git config --global http.postBuffer 157286400 # 150MB
TIP
After changing the buffer size, perform a pull followed by a push:
git pull && git push
2. Split Large Commits
If you have a single commit containing many files or large files, consider splitting it into smaller commits:
- Identify the problematic commit using
git log
- Undo to that commit using soft reset (preserves changes in staging):bash
git reset --soft HEAD~1
- Pull to sync with remote:
git pull
- Create multiple smaller commits and push them individually
3. Switch to SSH Protocol
HTTP and SSH protocols have different limitations. Switching to SSH can often resolve push issues:
# Change remote URL from HTTPS to SSH
git remote set-url origin git@github.com:username/repository.git
Then attempt to push again:
git push
WARNING
Ensure you have SSH keys properly configured before switching protocols.
4. Check Network Configuration
Network issues, particularly with VPN connections or MTU (Maximum Transmission Unit) settings, can cause this error:
# Temporarily lower MTU (Linux example)
sudo ip link set eth0 mtu 800
Try pushing again after adjusting network settings. You may also want to test with different network connections.
5. Verify Git Ignore Rules
Ensure you're not accidentally trying to push unnecessary large files:
# Check what files are being tracked
git ls-files --size | sort -n -r | head -10
Make sure your .gitignore
file excludes large directories like node_modules
, build artifacts, and other unnecessary files.
Advanced Solutions
Push Branches Individually
If you're pushing multiple branches, try pushing them one at a time:
# Push specific branch
git push origin branch-name
# Or push all branches individually
git push --all
Use Tracking References
Explicitly set upstream tracking references:
git push -u origin master
Check Server Limitations
Some Git hosting services have specific limitations on push size. Check your provider's documentation:
- GitHub: 100MB file size limit, 2GB repository size warning
- GitLab: Default 10MB push limit (configurable)
- Bitbucket: 2GB hard limit, 1GB recommended
Prevention Strategies
- Use Git LFS for large files: Track large files with Git Large File Storage
- Regular maintenance: Use
git gc
to optimize repository size - Avoid committing generated files: Use
.gitignore
effectively - Split large repositories: Consider splitting monorepos into smaller components
When All Else Fails
If none of these solutions work, consider these last resorts:
- Fresh clone and push: Clone the repository fresh and push to a new remote
- Mirror repository: Use
git clone --mirror
for complete repository migration - Archive and reinitialize: Archive the current state, create a new repository, and commit the archive
DANGER
Be extremely careful with force pushes (git push --force
) as they can overwrite history and cause data loss.
Conclusion
The "RPC failed; HTTP 400" error typically resolves with one of these approaches. Start with increasing the HTTP post buffer, then try splitting large commits or switching to SSH protocol. For persistent issues, examine network configurations and server limitations. Implementing proper repository maintenance practices will help prevent this issue in the future.