[Fixed] error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 in Git: Step-by-Step Troubleshooting Guide

Overview & Root Cause Summary: The error error: RPC failed; HTTP 413 curl 22 The requested URL returned error: 413 (often accompanied by send-pack: unexpected disconnect while reading sideband packet) occurs during git push over HTTPS when the payload of commits, binary objects, or historical packfiles exceeds the maximum allowable HTTP request body size enforced by Git’s internal buffer, an intermediary reverse proxy (like Nginx, Traefik, or Cloudflare), or the remote Git server.

Understanding the Root Causes

  • Default Git HTTP Buffer Limits: The default client-side http.postBuffer in Git is 1 MiB, which can choke when uploading large chunked packfiles over slower or proxy-monitored network connections.
  • Server & Reverse Proxy Size Caps: Self-hosted Git platforms (GitLab, Gitea, GitHub Enterprise) running behind Nginx or Apache terminate uploads when the request exceeds the web server’s client_max_body_size.
  • Uncompressed Binary Assets: Committing large binary files (e.g., zip archives, videos, model weights, machine learning datasets) directly into the Git tree instead of delegating them to Git LFS (Large File Storage).
  • WAF or CDN Restrictions: Corporate firewalls, Cloudflare, or edge proxies capping POST payloads at 100 MB or 500 MB.

Step 1: Quick Fix (Increase Git Client http.postBuffer)

Temporarily or globally increase the Git HTTP POST buffer size so Git can transfer larger packfiles in a single transmission without chunking timeouts.

# Set Git HTTP buffer to 500 MB globally:
git config --global http.postBuffer 524288000

# For repositories with very large assets, set to 1 GB:
git config --global http.postBuffer 1048576000

# Set Git to use HTTP 1.1 instead of HTTP/2 if stream disconnection occurs:
git config --global http.version HTTP/1.1

# Re-attempt the push:
git push origin $(git branch --show-current)

Step 2: Migrate Large Assets to Git LFS (Large File Storage)

If your commit contains large binaries, tracking them in standard Git history will bloat the repository and trigger 413 errors. Migrate them to Git LFS.

# 1. Install Git LFS:
git lfs install

# 2. Track large file extensions (e.g., zip, mp4, tar, bin):
git lfs track "*.zip" "*.tar.gz" "*.mp4" "*.bin"

# 3. Ensure .gitattributes is tracked and committed:
git add .gitattributes
git commit -m "chore: configure Git LFS tracking"

# 4. Migrate previously committed large files out of Git commit history:
git lfs migrate import --include="*.zip,*.tar.gz,*.mp4" --everything

# 5. Push LFS objects and branch references:
git push origin --force --all

Step 3: Server-Side Proxy Configuration & Switching to SSH

If you maintain a self-hosted Git server (GitLab / Gitea), adjust reverse proxy directives, or bypass HTTPS body limitations completely by switching to the SSH protocol.

# Option A: In Nginx configuration (nginx.conf or vhost):
# Increase maximum allowed body size for Git endpoints:
client_max_body_size 500M;

# Option B: Switch remote origin from HTTPS to SSH (bypasses HTTP limits entirely):
git remote set-url origin git@github.com:your-username/your-repo.git

# Verify SSH connection and push:
ssh -T git@github.com
git push origin $(git branch --show-current)

Verification & Testing Steps

Verify that your buffer configuration and Git LFS tracking are properly applied, and ensure that remote push commands complete successfully.

# 1. Confirm active postBuffer configuration:
git config --get http.postBuffer

# 2. Verify all tracked Git LFS assets:
git lfs ls-files

# 3. Perform a push and monitor transfer progress:
git push -u origin $(git branch --show-current)

Summary Comparison Table

Troubleshooting Method Applied Layer Payload Limit Relief Recommended Scenario
Increase http.postBuffer Client Git CLI Up to specified buffer (e.g. 500 MB) Large standard commit histories / initial push
Git LFS Migration Repository Architecture Unlimited (Asset offloading) Large media, binary datasets, and build artifacts
Nginx client_max_body_size Server Reverse Proxy Customizable by admin Self-hosted GitLab, Gitea, or GitHub Enterprise
Switch to SSH Protocol Transport Protocol Immune to HTTP body caps Permanent solution for developer workstations

Leave a Reply

Discover more from Victor's room

Subscribe now to keep reading and get access to the full archive.

Continue reading