Skip to main content
Back to blog

Self-hosting Gitea for private repositories

·3 min readSelf-Hosting

GitHub is where I host all my public code. But for private projects, experiments, and configuration repos, I run a Gitea instance on my homelab. It is lightweight, fast, and keeps my private code off someone else's servers.

Why not just use GitHub private repos?

GitHub's free tier includes unlimited private repos, so the question is fair. My reasons:

Data sovereignty. Private repos on GitHub are still on Microsoft's infrastructure. For personal projects this might be fine, but I prefer keeping certain things (like my homelab configuration, including secrets templates and infrastructure notes) on my own hardware.

No limits. GitHub has file size limits, LFS storage costs, and action minutes quotas. On my own server, I push whatever I want without thinking about it.

It was easy. Setting up Gitea took 10 minutes. It runs in a single Docker container and uses minimal resources. The effort-to-benefit ratio was excellent.

Setting it up

services:
  gitea:
    image: gitea/gitea:latest
    container_name: gitea
    restart: unless-stopped
    ports:
      - "3000:3000"
      - "2222:22"
    volumes:
      - ./gitea-data:/data
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=sqlite3

Access it at http://your-server:3000, run through the setup wizard, and create your first repo. SQLite is fine for personal use. If you want PostgreSQL, add a database container like any other Docker setup.

Add a Caddy entry for HTTPS:

gitea.example.com {
    reverse_proxy localhost:3000
}

SSH access

The port mapping 2222:22 lets you push and pull over SSH. Add the SSH URL to your config:

Host gitea
    HostName your-server-ip
    User git
    Port 2222
    IdentityFile ~/.ssh/id_ed25519

Now you can clone with git clone gitea:username/repo.git.

Mirroring from GitHub

Gitea can mirror repositories from GitHub automatically. If you want a local backup of your public repos or want to keep a fork in sync, set up a mirror:

Repository Settings > Mirror Settings > Add the GitHub URL. Gitea pulls changes on a schedule.

I mirror a few of my GitHub repos to Gitea as a backup. If GitHub has an outage or I lose access to my account, I have a complete copy of every repo locally.

The interface

Gitea's web UI is a lightweight clone of GitHub's interface. Issues, pull requests, code review, wiki, and releases are all there. It is not as feature-rich as GitHub, but for personal use it has everything I need.

The resource usage is minimal. Gitea runs comfortably on 256MB of RAM and barely touches the CPU. It is one of the lightest self-hosted services I run.

When GitHub is better

For public open-source projects, GitHub is the right choice. The network effect matters: contributors find your project through GitHub, CI/CD integrations are seamless, and the community features (discussions, sponsors, actions) are excellent.

For private repos where you want control, a self-hosted Gitea instance is a nice complement to GitHub.

Sources

Enjoying the blog? Subscribe via RSS to get new posts in your reader.

Subscribe via RSS