How to Run a Private Git Server on Your VPS with Gitea

How to Run a Private Git Server on Your VPS with Gitea

A self-hosted Git server puts your code on hardware you control. Gitea is a light, open-source git service that runs well on a small server, and it gives you a web UI, pull requests, and issue tracking without handing your repos to a third party. This guide walks through the full setup: a Docker install, a reverse proxy with HTTPS, and the daily workflow of creating repos, cloning, and pushing. If you already run a VPS for other self-hosted apps, Gitea is a natural next step.

Why run a private git server on your VPS

Most developers start on GitHub, and for public work that still makes sense. Self-hosting Git earns its place when you want full control: your code never leaves your own disk, you set the storage limits, and no plan change on someone else’s platform can lock you out of your repos. It also works well for private projects, client work under NDA, and config files you do not want on a public host.

A self-hosted git server also fits a homelab or small-team workflow. You get the same basic flow as any hosted service, clone, commit, push, review, but the server, the data, and the backup plan are all yours. The trade is simple: you take on the maintenance. Gitea keeps that job small. It is a single binary with low memory use, and the Docker image runs fine on a 1 GB VPS next to a few other services.

What you need before you start

You need a VPS with Docker and Docker Compose installed, a domain or subdomain pointed at the server, and SSH access. A 1 GB RAM VPS is enough for a personal instance with a handful of users. If Docker is not installed yet, follow the steps to install Docker Compose on Ubuntu 24.04 first, then come back here.

Pick a subdomain like git.yourdomain.com and create an A record pointing to your VPS IP. DNS changes can take a few minutes to spread, so set the record before you start the install. You will also want a firewall that allows ports 22, 80, and 443, and nothing else open to the internet.

Gitea Docker setup: install with Compose

The fastest way to run Gitea is the official Docker image with a small Compose file. Create a folder for it and a data volume so your repos survive container restarts.

mkdir -p /opt/gitea/data
cd /opt/gitea
nano docker-compose.yml

Paste this Compose file. It runs Gitea and a SQLite database, which is fine for a personal or small-team instance. If you expect dozens of users, switch the database to PostgreSQL later.

services:
  gitea:
    image: gitea/gitea:1.23
    container_name: gitea
    environment:
      - USER_UID=1000
      - USER_GID=1000
      - GITEA__database__DB_TYPE=sqlite3
      - GITEA__database__PATH=/data/gitea/gitea.db
    restart: always
    volumes:
      - ./data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "2222:22"

Start it and check the logs. If you are new to Compose files, the Docker Compose basics guide explains each block in this file so you can adjust it with confidence.

docker compose up -d
docker compose logs -f gitea

When the logs show the server listening on port 3000, open http://your-server-ip:3000 in a browser. The first-run page asks for a database, site title, and an admin account. Keep SQLite, set the server domain to your subdomain, and create the admin user. That admin account is the only one that can change server settings, so use a long password and store it in a password manager.

Put Gitea behind a reverse proxy

Gitea should not sit on port 3000 in public. A reverse proxy in front of it gives you a clean URL and HTTPS. If Nginx is already on your server, add a server block for the subdomain that proxies to localhost:3000, then get a certificate. The steps to get free SSL certificates with Let’s Encrypt cover the cert part in detail.

server {
    listen 80;
    server_name git.yourdomain.com;
    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

After the certificate is in place, test the site at https://git.yourdomain.com. Log in as the admin you created, open Site Administration, and confirm the app URL shows the HTTPS address. If the app URL still shows HTTP, fix it in the admin settings, or Gitea will build clone URLs with the wrong scheme. For a full walkthrough of the proxy part, see the Nginx reverse proxy setup guide.

Daily use: create a repo, clone, and push

Day-to-day work with Gitea feels the same as any git host. Create a repo from the web UI, pick a name, and choose private or public. Gitea shows you the clone URL right away. On your local machine, clone it over SSH or HTTPS.

git clone [email protected]:username/my-project.git
cd my-project

Work as normal: edit files, commit, and push. Pull requests work the same way too. Make a branch, push it, and open a pull request from the web UI. Your teammates can review the diff, leave comments, and merge when it is ready. Issues live next to the code, so you can track bugs without a separate tool.

For SSH cloning, each user adds their public key in their Gitea profile settings. The SSH port is 2222 in the Compose file above, so clone URLs use that port. If you use the standard port 22 for SSH on the server itself, keep Gitea on 2222 to avoid a clash, and make sure port 2222 is open in your firewall.

Gitea vs GitHub: what you give up

A gitea vs github comparison comes down to scale and convenience. GitHub offers Actions, a huge marketplace, hosted runners, and a social layer where other developers can find your work. Gitea has Actions too, but you run the runners yourself, and there is no built-in discovery. If your project needs public visibility or a big contributor base, GitHub is the better home for it.

What Gitea gives you instead is control and a small footprint. No per-seat billing, no storage tier to watch, and no terms change that can affect your repos. The cost is your time: you patch the server, watch disk space, and keep backups. For private projects, client code, and personal tools, that trade usually pays off. For open-source projects that want contributors, keep them on GitHub and mirror a copy to Gitea if you want your own backup.

Keep your repos safe: backups and updates

A git server holds work you cannot afford to lose, so set up backups on day one, not after the first scare. The repo data and the SQLite database both live in the /opt/gitea/data folder from the Compose file. Back up that folder nightly to a second location, off the server. The guide to back up Docker volumes automatically shows a simple way to do this with a scheduled job.

Updates are simple too. Pull the new image, restart the container, and check the release notes first for any database migration notes.

cd /opt/gitea
docker compose pull
docker compose up -d

Test the site after each update and confirm you can still clone a repo. If something breaks, the data folder is your safety net: stop the container, restore the folder from backup, and start the old image again. Your Gitea install is only as safe as its last tested backup, so restore one backup to a test folder at least once and confirm the repos open.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.