This error occurs when pushing data to a Git server that exceeds the server's configured maximum pack size limit. Common with large repositories, big binary files, or when pushing many commits at once.
When you push to a Git server (GitHub, GitLab, Bitbucket, or self-hosted), Git packages your commits and files into a "pack file" for efficient transfer. The remote server has a configured limit on how large this pack can be to prevent denial-of-service attacks and manage resources. GitHub limits individual pushes to 2 GB, GitLab.com has a 10 GB repository limit (free tier) with 1 GB per file by default, and self-hosted servers may have custom limits set via `receive.maxInputSize` or similar configurations. The error typically appears as "remote: fatal: pack exceeds maximum allowed size" followed by connection errors like "fatal: the remote end hung up unexpectedly". This is fundamentally a server-side protection mechanism, though the solution often involves client-side adjustments to how you push data. The pack size depends on both the number of commits and the size of files being transferred, not just the total repository size.
Check your Git hosting provider's documentation for push size limits:
- GitHub: 2 GB maximum per push
- GitLab.com: 10 GB repository limit (free tier), ask admins about push limits
- Bitbucket Cloud: Typically 2-4 GB limits
- Self-hosted: Check with your Git administrator
If you're under the limit and still seeing this error, the issue may be with intermediate proxies or misconfiguration.
Instead of pushing all commits at once, push earlier commits first, then gradually add more:
# Push an early commit to create the branch
git push origin <early-commit-sha>:refs/heads/main
# Push a commit halfway through history
git push origin <middle-commit-sha>:refs/heads/main
# Finally push the latest
git push origin mainFor systematic incremental pushes:
# Push in batches of 500 commits
git push origin main~2000:main
git push origin main~1500:main
git push origin main~1000:main
git push origin main~500:main
git push origin mainAdjust the step size based on your repository. If a single commit is too large, this won't help—you'll need to split the commit or use Git LFS.
Use git-sizer to analyze what's consuming space:
# Install git-sizer (macOS)
brew install git-sizer
# Or download from https://github.com/github/git-sizer/releases
# Analyze your repository
git-sizer --verboseIf large files are identified, migrate them to Git LFS:
# Install Git LFS
git lfs install
# Track large file types
git lfs track "*.psd"
git lfs track "*.zip"
git lfs track "*.mp4"
# Migrate existing files in history (WARNING: rewrites history)
git lfs migrate import --include="*.psd,*.zip" --everything
# Push LFS files
git lfs push --all origin
# Push Git commits
git push origin mainWarning: git lfs migrate rewrites history. Coordinate with your team before running this on shared branches.
While often suggested, http.postBuffer only helps with buggy proxies that don't support HTTP/1.1 chunked transfer encoding. Try it, but don't expect it to solve server-side pack limits:
# Increase buffer to 500 MB
git config --global http.postBuffer 524288000
# Or up to 2 GB (maximum practical value)
git config --global http.postBuffer 2000000000This adjusts how Git buffers data locally before sending it. It does not change the server's maximum pack size limit.
If you control the Git server, increase the receive limits:
GitLab (self-hosted):
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['max_push_size'] = 5.gigabytesThen reconfigure:
sudo gitlab-ctl reconfigureGitea/Gitolite:
Increase receive.maxInputSize in Git config:
git config --system receive.maxInputSize 5gReverse proxy (nginx):
Increase client_max_body_size in nginx config:
http {
client_max_body_size 2G;
}Reload nginx: sudo nginx -s reload
If your local repository is bloated and you don't need full history, create a shallow clone:
# Clone only recent history
git clone --depth 1 https://github.com/user/repo.git
cd repo
# Add new remote
git remote add new-origin https://new-server.com/user/repo.git
# Push shallow history
git push new-origin mainThis reduces the pack size by excluding historical commits. Use --depth 100 for more history if needed.
Why http.postBuffer is overrated: Git's documentation explicitly warns against using http.postBuffer as a general solution. It only helps when proxies don't support HTTP/1.1 chunked encoding, which is rare in 2025. Most "pack exceeds maximum" errors are true server-side limits, not client buffering issues.
GitHub's 2 GB limit: This is a hard limit per push, not per file or per repository. GitHub enforces this to prevent abuse and maintain service reliability. The GitHub import utility has different (higher) limits for migrations.
Splitting large commits: If a single commit contains files exceeding the limit, you cannot push it incrementally—the commit is atomic. Your options are: (1) amend the commit to remove large files, (2) rewrite history with git filter-repo or git filter-branch to split the commit, or (3) migrate large files to Git LFS and rewrite history.
Network vs. server limits: Don't confuse "pack exceeds maximum" with generic network failures like "RPC failed" or "hung up unexpectedly". The former is a configured server limit; the latter can be network timeouts, proxy issues, or authentication problems. They sometimes appear together, but require different solutions.
Best practices: Store large binary files (images, videos, compiled binaries) in Git LFS from the start. Keep repositories focused—use submodules or separate repos for different components rather than monolithic repositories. For migrations, consider repository forks or export/import tools provided by your Git host.
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