A Private Git Forge Needs a Named Owner
Git made repository history portable. Web forges gathered reviews, permissions, issue tracking, and automation around it, putting central coordination back into distributed version control.
Self-host when control over access, deployment timing, or network boundaries justifies owning the service. Choose a hosted forge when repository administration would compete with the work those repositories support.
A developer’s clone can rescue committed code. Review discussions, access rules, and webhook settings live elsewhere. Someone must own that state and the service around it. A lightweight executable still comes with an on-call job.
Choose the Forge Around Its Operational Dependencies
Which should you run: Forgejo or Gitea? Start with required integrations, authentication support, compatible runners, release documentation, and packaging for your Linux host. Those dependencies make a better selection process than screenshots of nearly identical repository pages.
This walkthrough uses Forgejo, SQLite, systemd, and persistent SSD storage. Gitea readers should use the equivalent settings and supported runner for their selected release. Heavy concurrent database writes warrant choosing an external database before installation.
Size disk capacity around repository history, LFS objects, attachments, package artifacts, logs, and backup staging. Repository count tells you remarkably little about storage demand. Include recovery copies in the capacity calculation.
Run a Verified Forgejo Binary Behind HTTPS
Select an explicit Forgejo release and your host’s architecture. Download its binary and detached signature, then follow that release’s published verification procedure using an authenticated signing key. Keep the release identifier with your deployment notes; a moving “latest” download defeats reproducibility.
After successful verification, set VERIFIED_BINARY to the downloaded file’s path. Run these commands as root:
useradd --system --user-group --create-home \
--home-dir /home/git --shell /usr/sbin/nologin git
install -d -o git -g git -m 0750 \
/etc/forgejo /var/lib/forgejo \
/var/lib/forgejo/data /var/lib/forgejo/repositories
install -o root -g root -m 0755 \
"$VERIFIED_BINARY" /usr/local/bin/forgejo
/usr/local/bin/forgejo --version
Create /etc/systemd/system/forgejo.service:
[Unit]
Description=Forgejo
After=network.target
[Service]
User=git
Group=git
WorkingDirectory=/var/lib/forgejo
Environment=USER=git HOME=/home/git
ExecStart=/usr/local/bin/forgejo web --work-path /var/lib/forgejo --config /etc/forgejo/app.ini
Restart=on-failure
UMask=0027
[Install]
WantedBy=multi-user.target
Keep HTTP on Loopback
Start with this app.ini, owned by git:git with mode 0640:
[database]
DB_TYPE = sqlite3
PATH = /var/lib/forgejo/data/forgejo.db
[repository]
ROOT = /var/lib/forgejo/repositories
[server]
APP_DATA_PATH = /var/lib/forgejo/data
HTTP_ADDR = 127.0.0.1
HTTP_PORT = 3000
[service]
DISABLE_REGISTRATION = true
Use a local HTTPS reverse proxy. For example, this Caddy configuration obtains and serves a certificate when DNS and inbound certificate validation are correctly configured:
forge.example.net {
reverse_proxy 127.0.0.1:3000
}
Restrict initial access to your administrative network. Start Forgejo, complete its installer, retain the paths above, set ROOT_URL to the public HTTPS address, and create the administrator account. Confirm INSTALL_LOCK = true under [security] afterward.
systemctl daemon-reload
systemctl enable --now forgejo.service
After setup, make app.ini root-owned and group-readable by git. Reboot and check HTTPS access, certificate validity, and disabled public registration.
Give Git SSH Its Own Port and Recovery Route
A working browser login says nothing about clone URLs. Configure Forgejo’s built-in SSH server in the existing [server] section:
START_SSH_SERVER = true
SSH_DOMAIN = forge.example.net
SSH_USER = git
SSH_LISTEN_PORT = 2222
SSH_PORT = 2222
Allow inbound TCP port 2222 through the host and network firewalls, then restart Forgejo. Keep administrative OpenSSH separately accessible on its existing port. With no port translation here, the listener, firewall allowance, and advertised clone port must agree.
Developers add public keys through their forge accounts. Keep repository files under the service account’s control; developers need no interactive host accounts.
From a separate client, verify the built-in server’s host-key fingerprint through a trusted administrative channel. Clone a disposable repository using the displayed SSH address, push a commit, and confirm that an interactive SSH request provides no shell.
Enable administrator MFA and store recovery codes outside the forge. Test account recovery before that account becomes the only way to repair permissions.
Move GitHub Repositories With One Writable Primary
A pull mirror keeps copying an upstream repository into the forge. A migration establishes a new primary. Choose explicitly: competing writable locations create competing histories.
Mirror Pushes Delete Refs
The destination must be empty. A mirror push can overwrite destination refs and delete refs absent from the local mirror.
For a Git-only cutover, pause source writes. Set SOURCE and DESTINATION to the respective Git addresses:
git clone --mirror "$SOURCE" migration.git
cd migration.git
# Run the LFS commands when this repository uses LFS.
git lfs fetch --all origin
git push --mirror "$DESTINATION"
git lfs push --all "$DESTINATION"
git ls-remote --heads --tags "$SOURCE"
git ls-remote --heads --tags "$DESTINATION"
Compare branch and tag names and object IDs. Make a fresh destination clone and download its LFS content. Git-only transfer covers Git history; plan issue and review migration separately. Update developer remotes and automation, then archive the source read-only.
Put Workflow Execution on a Separate Worker
Your first successful workflow should run on another host or VM. Install a Forgejo-compatible forgejo-runner release and follow its registration procedure for the selected server version. Start with repository-scoped registration and a disposable test repository.
Workflow code executes commands. Registration scope and accepted repositories determine who can exercise that worker’s privileges. Keep forge data, backup credentials, and administrator tokens off it. Retain only the runner authentication material required to operate it, protected from jobs.
Mounting a host container socket gives jobs powerful control over that host. For external pull requests, restrict secret exposure and use disposable VM execution. Check that a test job returns its log over HTTPS and leaves no job secrets behind.
Restore SQLite and Forge Files as One Recovery Set
Backups need a restore test. Capture the database, repositories, LFS objects, attachments, package data, configuration, encryption secrets, and application version together.
For this layout, stop writes while copying state. Use a restricted staging directory:
set -eu
umask 077
BACKUP_DIR=$(mktemp -d /root/forgejo-backup.XXXXXX)
/usr/local/bin/forgejo --version > "$BACKUP_DIR/version.txt"
systemctl stop forgejo.service
trap 'systemctl start forgejo.service' EXIT
tar -C / -cpf "$BACKUP_DIR/state.tar" \
etc/forgejo var/lib/forgejo
systemctl start forgejo.service
trap - EXIT
Investigate any copy failure before treating the archive as usable. Transfer successful recovery sets to separately protected storage using credentials distinct from normal forge access. Set frequency from acceptable lost work and retention from recovery needs.
Prove the Restore
Restore onto a network-fenced host running the recorded binary. Verify MFA login, clone and push, an existing attachment, and an LFS download. Preserve app.ini: its secrets belong with the state they protect.
Upgrade With the Pre-Migration Database Within Reach
Read the target release’s upgrade notes and supported version path. Check configuration changes and runner compatibility. Rehearse the exact binary replacement against an isolated restored copy, watching database migrations and startup.
During an announced maintenance window, take a fresh consistent recovery set, install the verified pinned binary, and start Forgejo. Database migrations can make an older executable incompatible with the changed state. Recovery requires the matching pre-upgrade database, repository state, configuration, and binary.
Keep that archive pinned. From your separate client, push a disposable commit, open its diff in the browser, and watch the isolated worker return a green job beside it.
Your Thoughts
Share your thoughts.
Join the Discussion