Home / Guides / Gitea

Your own Git server with Gitea

Gitea is a lightweight Git service with issues, pull requests and CI hooks — everything you expect, running in a few hundred megabytes. On a €6.5 VPS it serves a whole team.

1. Install Docker

apt update && apt install -y docker.io docker-compose-v2 git
systemctl enable --now docker

Full walkthrough including Compose basics: Docker guide.

2. Compose file

mkdir -p /opt/gitea && cd /opt/gitea
cat > docker-compose.yml <<'EOF'
services:
  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: change-me-db
      POSTGRES_DB: gitea
    volumes:
      - ./db:/var/lib/postgresql/data
  gitea:
    image: gitea/gitea:1
    restart: unless-stopped
    depends_on: [db]
    environment:
      GITEA__database__DB_TYPE: postgres
      GITEA__database__HOST: db:5432
      GITEA__database__NAME: gitea
      GITEA__database__USER: gitea
      GITEA__database__PASSWD: change-me-db
    volumes:
      - ./data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "127.0.0.1:3000:3000"
      - "2222:22"
EOF
docker compose up -d

Note the bindings: the web UI listens on localhost only, while SSH for git push is on port 2222. Make the port reachable — either open 2222 in the firewall, or later serve Git over HTTPS.

3. HTTPS with Caddy

apt install -y caddy
cat > /etc/caddy/Caddyfile <<'EOF'
git.example.com {
    reverse_proxy 127.0.0.1:3000
}
EOF
systemctl reload caddy

Caddy fetches a certificate automatically. Point the domain's A record at the server first, and finish the setup wizard in the browser — the first account you register becomes the administrator.

4. Push code

git remote add origin ssh://[email protected]:2222/you/project.git
git push -u origin main

Add your public key in Gitea's settings once, and every push after that is password-free.

5. Backups that actually restore

docker compose exec -u git gitea gitea dump -c /data/gitea/conf/app.ini
# the dump lands in /opt/gitea/data/gitea, then ship it off-site:
restic backup /opt/gitea/data --exclude-caches

The gitea dump command bundles the database, repositories and configuration into one archive. Off-site copies: see the restic guide.

Quick answers

How much RAM does Gitea need?

The container idles around 150–250 MB, PostgreSQL another 100–200 MB. A 2 GB server is comfortable for a small team; 4 GB if you also run CI runners or many large repositories.

Can I import repositories from GitHub?

Yes. In Gitea choose New Migration, paste the repository URL, and it copies code, issues and pull requests. Private repositories need a GitHub access token.

Is my code safe on a VPS?

It is as safe as your server administration: SSH keys, firewall, updates and off-site dumps cover the realistic risks. For many teams that is more control than trusting a third party with everything.

Gitea plus PostgreSQL fit Buran-2 (€13/mo) with room to spare.

Related