Back to Blog
gitgiteaself-hostingdevopstutorial

Run Your Own Git Server: Self-Hosting Gitea with InfraPilot

I

InfraPilot Team

March 20, 2026

Why Self-Host Your Git Server?

GitHub, GitLab, and Bitbucket are all excellent — but they charge per seat for private repos or advanced features, and your code lives on their infrastructure. Self-hosting Gitea gives you unlimited private repos, CI/CD hooks, issue tracking, and a GitHub-like interface, all on your own server for the cost of a VPS.

Gitea is built in Go — the server binary uses under 50 MB of RAM at idle. It runs comfortably on a $6/mo VPS alongside other services.

Prerequisites

  • VPS with Docker installed
  • InfraPilot installed: curl -fsSL https://infrapilot.org/install.sh | bash
  • A subdomain for Gitea (e.g. git.yourdomain.com)

Step 1 — Create the Compose Stack

mkdir -p ~/apps/gitea && cd ~/apps/gitea
services:
  gitea:
    image: gitea/gitea:1-rootless
    restart: unless-stopped
    environment:
      GITEA__database__DB_TYPE: postgres
      GITEA__database__HOST: db:5432
      GITEA__database__NAME: gitea
      GITEA__database__USER: gitea
      GITEA__database__PASSWD: ${DB_PASSWORD}
      GITEA__server__DOMAIN: git.yourdomain.com
      GITEA__server__ROOT_URL: https://git.yourdomain.com
      GITEA__server__HTTP_PORT: 3000
      GITEA__server__SSH_PORT: 2222
      GITEA__server__SSH_LISTEN_PORT: 2222
    ports:
      - "3010:3000"
      - "2222:2222"
    volumes:
      - gitea_data:/var/lib/gitea
      - gitea_config:/etc/gitea
    depends_on:
      - db

  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: gitea
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - db_data:/var/lib/postgresql/data

volumes:
  gitea_data:
  gitea_config:
  db_data:

Create .env:

DB_PASSWORD=strong-gitea-db-password
docker compose up -d

Step 2 — Configure the Reverse Proxy in InfraPilot

  1. InfraPilot → Traffic → Proxy Hosts → Add Proxy Host
  2. Domain: git.yourdomain.com
  3. Forward host: gitea, port: 3000
  4. Enable Let's Encrypt SSL, force HTTPS
  5. Enable WebSocket support (needed for the Gitea UI)

Step 3 — Initial Gitea Setup

Visit https://git.yourdomain.com — you'll see the Gitea installation wizard. Most settings are pre-filled from the environment variables. Set your admin account credentials and click Install Gitea.

SSH Push/Pull

For SSH access to repositories, Gitea listens on port 2222. Your server firewall must allow this port. Clone repos with:

git clone ssh://git@git.yourdomain.com:2222/user/repo.git

Or add an SSH config entry:

Host git.yourdomain.com
    Port 2222
    User git

Then clone normally: git clone git@git.yourdomain.com:user/repo.git

Monitoring Gitea with InfraPilot

Gitea is extremely lightweight — you'll typically see the container using under 100 MB RAM. InfraPilot's unified logs let you watch for failed login attempts or push errors without SSHing into the server. Set up an alert to notify you if the Gitea container restarts unexpectedly.