When pushing a large repository with extensive history to my self-hosted Forgejo instance, I kept running into Connection reset by peer errors during HTTP git push. After trying various timeout configurations and SSH settings, I found a reliable workaround: uploading the bare repository directly to the NFS storage that backs Forgejo.

The Problem

Pushing large repos over HTTP or SSH to Forgejo can fail with:

error: RPC failed; curl 92 HTTP/2 stream 5 was not closed cleanly: CANCEL (err 8)
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

This happens even with increased timeout settings like PER_WRITE_TIMEOUT and PER_WRITE_PER_KB_TIMEOUT.

The Solution

Instead of pushing through Forgejo, create a bare clone of your repository and upload it directly to the underlying storage.

Step 1: Create a Bare Clone

git clone --bare . /tmp/myrepo.git

This creates a bare repository (no working directory) containing all your git history.

Step 2: Compress for Transfer

cd /tmp
tar -czf myrepo.git.tar.gz myrepo.git

Step 3: Upload to NFS Storage

Transfer the compressed archive to your NFS storage. If you’re using a Synology NAS like me, the path is typically:

/volume1/data/git/{username}/

You can use scp, rsync, or mount the NFS share directly.

Step 4: Extract and Set Permissions

SSH into your storage server or Forgejo pod and extract:

cd /path/to/git/repos/{username}
# Backup existing if needed
mv myrepo.git myrepo.git.bak
tar -xzf myrepo.git.tar.gz
# Set correct ownership for Forgejo
chown -R 1024:users myrepo.git

The UID 1024 matches the default Forgejo user. Adjust based on your setup.

Step 5: Verify

  1. Check the repository in Forgejo’s web UI
  2. Try cloning it: git clone https://forgejo.example.com/user/myrepo.git
  3. Verify branches and history are intact

Important: Regenerate Git Hooks

After uploading via NFS, the repository won’t have Forgejo’s git hooks. This means Actions workflows won’t trigger on push events. Run this in the Forgejo container:

forgejo admin regenerate hooks

I wrote a separate post about fixing missing git hooks after NFS uploads.

When to Use This Approach

  • Large repositories (10GB+) with extensive commit history
  • When HTTP push times out repeatedly
  • Initial migration of existing repos to self-hosted Forgejo
  • Repositories with large binary files in history

For normal day-to-day operations, standard git push works fine. This is specifically for those edge cases where the repository is too large for a clean HTTP transfer.