Self-Hosting Your Own Git Server with Gitea
#gitea
#self-hosting
#git-server
#docker
#tutorial
Introduction
Self-hosted Git servers give you full control over access, backups, and integrations. Gitea is a popular, lightweight option that runs quickly on modest hardware and ships with a friendly web UI, SSH access, and an API. This guide walks you through a practical setup using Docker Compose, so you can host a private Git server for your team or personal projects.
Why choose Gitea for self-hosting
- Lightweight and fast: very small resource footprint compared to larger platforms.
- Easy to install: single binary in typical deployments, plus Docker support.
- Built-in features: code hosting, issue tracking, wiki, pull requests, and webhooks.
- Flexible deployment: works behind a reverse proxy with TLS termination.
Prerequisites
- A server you control (VPS or dedicated) with Linux (Ubuntu/Debian recommended).
- A domain name or static IP for access (optional but recommended).
- Basic familiarity with Docker and Docker Compose.
- Ports 80/443 available for TLS termination if you plan to use a domain.
Quick start with Docker Compose
This approach runs Gitea with PostgreSQL as the database and exposes the web UI on port 3000 (behind a reverse proxy if you configure TLS).
# docker-compose.yaml
version: '3.8'
services:
db:
image: postgres:15
restart: unless-stopped
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: gitea
POSTGRES_PASSWORD: gitea123
POSTGRES_DB: gitea
gitea:
image: gitea/gitea:1.19.0
depends_on:
- db
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=db:5432
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASS=gitea123
- GITEA__server__ROOT_URL=https://git.example.com/
restart: unless-stopped
volumes:
- gitea-data:/data
ports:
- "3000:3000"
- "22:22"
volumes:
db-data:
gitea-data:
Steps to run:
- On your server, create a directory for the project and place docker-compose.yaml there.
- Run: docker compose up -d
- Wait a minute or two for Gitea to initialize, then visit http://
:3000 or your domain if you’re using a reverse proxy.
Domain, TLS, and reverse proxy considerations
- If you’re using a domain (recommended), point an A/AAAA record to your server and set ROOT_URL in the Gitea environment to your domain (e.g., https://git.yourdomain.com/).
- For TLS, place a reverse proxy in front of Gitea (e.g., Nginx, Traefik, or Caddy) and terminate TLS there. If you use Nginx:
- Configure a server block for your domain that proxies requests to http://localhost:3000.
- Enable TLS with Let’s Encrypt or your certificate.
- You can also deploy Gitea behind Traefik with automatic Let’s Encrypt certificates.
Example Nginx snippet (simplified):
- server_name git.yourdomain.com;
- location / { proxy_pass http://localhost:3000; }
Remember to adjust ROOT_URL to reflect the public URL you expose to users.
First run and basic configuration
- Open your domain or IP in a browser and complete the initial setup wizard.
- Create an admin user and connect at least one repository.
- Enable SSH access for git operations and configure your SSH keys for collaborators.
- In Gitea, configure user permissions, repository visibility, and webhook defaults as needed.
Security and best practices
- Keep your Gitea image up to date by pulling the latest tag and restarting containers after updates.
- Use a strong admin password and limit admin access to trusted accounts.
- Enable TLS at the reverse proxy to encrypt in transit.
- Regularly back up data:
- /path/to/gitea-data (the Gitea data directory)
- /path/to/db-data (PostgreSQL data)
- Consider separate users for deployment tasks and restrict SSH access to trusted keys.
- Disable or tightly control unnecessary services (e.g., SSH if you don’t need it publicly).
Maintenance and upgrades
- To upgrade Gitea, pull the latest image and recreate the containers:
- docker compose pull
- docker compose up -d
- Test the upgrade in a staging environment if possible, especially if you rely on custom hooks or plugins.
Conclusion
Gitea provides a compact, capable foundation for self-hosted Git workflows. With Docker Compose, you can get a private Git server up quickly while keeping the setup approachable for ongoing maintenance. By pairing Gitea with a TLS-enabled reverse proxy, you gain a secure, accessible hub for your code, issues, and collaboration.