Guideschevron_rightServers

Servers · 9 min read · Updated

How to Self-Host a Git Server with Forgejo

To self-host a Git server, run Forgejo with Docker Compose behind Caddy for HTTPS: one container holds the web interface, Git over SSH and a SQLite database in a single data folder. Point a domain at the VPS, start the containers, finish the setup page with your domain and SSH port, turn off open registration, and back up the data folder. A small team fits on the smallest VPS (6 GB, $37.50 a month); CI runners are what need the bigger server.

1. Prepare the Server

Order a VPS with Ubuntu 24.04, secure it, and install Docker. Point an A record such as git.example.com at it, and allow ports 80, 443 and 222 in the firewall.

2. Write the Compose File

In ~/forgejo, create the data folder owned by the user the container runs as, then compose.yaml:

mkdir -p ~/forgejo/data && cd ~/forgejo
sudo chown 1000:1000 data
services:
  forgejo:
    image: codeberg.org/forgejo/forgejo:17
    container_name: forgejo
    restart: always
    environment:
      - USER_UID=1000
      - USER_GID=1000
    volumes:
      - ./data:/data
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "222:22"              # Git over SSH

  caddy:
    image: caddy:2
    container_name: caddy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./caddy-data:/data
      - ./caddy-config:/config
# Caddyfile
git.example.com {
    reverse_proxy forgejo:3000
}

The number in the image tag is Forgejo's major version and follows its minor updates; 17 was current when this was written. Moving to the next major version needs a manual step, so check Forgejo's release notes first.

docker compose up -d
docker compose logs -f

3. Finish the Setup Page

Open https://git.example.com. On the first page:

  • Database: SQLite3 is fine for a team; it lives in the data folder.
  • Server domain: git.example.com; SSH server port: 222.
  • Base URL: https://git.example.com/.
  • Under the optional settings, disable self-registration unless the server is meant to be public.
  • Create the administrator account in the last section.

4. Push Over SSH

Add your public key under Settings → SSH / GPG keys, then clone with the port in the address:

git clone ssh://[email protected]:222/you/project.git

Or let plain addresses work by adding this to ~/.ssh/config on your computer:

Host git.example.com
    Port 222
    User git

5. CI With Forgejo Actions

Forgejo Actions reads workflow files much like GitHub Actions, and runs them on a separate program, Forgejo Runner. Install it on the same server for light use, or on a second, larger server so builds never slow the Git server down, and register it with a token from Site administration → Actions → Runners. The same reasoning as for a self-hosted GitHub runner applies: a runner with Docker access is effectively root on its server, so keep it to code you trust.

Backups and Updates

Repositories, the database, attachments and settings are all in ~/forgejo/data. For a clean copy, stop Forgejo for the moment it takes to archive it:

cd ~/forgejo
docker compose stop forgejo
sudo tar czf /var/backups/forgejo-$(date +%F).tar.gz data
docker compose start forgejo

Then send the archive off the server, to a storage box or with Borg, from a nightly timer. Update within the major version with docker compose pull && docker compose up -d, after a backup.

Common Questions

  • What is Forgejo?

    A free, open-source Git hosting server with repositories, pull requests, issues, a package registry and built-in CI called Forgejo Actions. It began as a community fork of Gitea and is developed under the Codeberg non-profit.

  • How much server does Forgejo need?

    Forgejo itself is light: a team's repositories run on a small VPS with SQLite. CI jobs are what need cores and memory, so run them on a separate runner, or move to a larger server when builds queue up.

  • Can I move my repositories from GitHub or GitLab?

    Yes. Use New Migration in Forgejo and choose the source: it can copy the repository with its issues, pull requests, labels, milestones and releases, given an access token for the old service. It can also keep a mirror in sync.

  • Why is Git over SSH on port 222?

    Port 22 is already used by the server's own SSH. Mapping the container's SSH to 222 keeps both; clone with the port in the address, or add a short entry to ~/.ssh/config so plain git@ addresses work.

Plans and prices

VPS Plans

KVM servers with NVMe storage and full root access: your code on a server you control.

See all plans
  • Bronze

    3 vCPU · 6 GB RAM · 75 GB NVMe

    2 TB transfer

    $37.50/mo

    Configure inAshburnDallas
  • Silver

    4 vCPU · 8 GB RAM · 100 GB NVMe

    4 TB transfer

    $46.50/mo

    Configure inAshburnDallas
  • Gold

    6 vCPU · 12 GB RAM · 150 GB NVMe

    6 TB transfer

    $60.00/mo

    Configure inAshburnDallas
  • Diamond

    8 vCPU · 16 GB RAM · 200 GB NVMe

    8 TB transfer

    $73.50/mo

    Configure inAshburnDallas

Network port: 10 Gbps in Ashburn, VA, 50 Gbps in Dallas, TX. Pick the location when you configure.

Keep Reading

All guides