Gitea Installation: Build Your Own High-Performance, Low-Cost Git Server

Git tutorial - IT technology blog
Git tutorial - IT technology blog

6 Months Living with Gitea: Why I Broke Up with GitLab

When I first started my outsourcing team, I was eager to install GitLab because I “heard” it was the most professional. That was where the mistake began. My 4GB RAM VPS, costing $20/month at the time, would frequently freeze, and the CPU would spike to 100% every time the team pushed code. After a week of stress, I decided to switch to Gitea and realized this was the true “soulmate.”

Gitea is written in Go, making it extremely lightweight. In a real-world scenario for a 10-person team, I checked the resources and found it only consumed a mere 120MB – 150MB of RAM. You can run Gitea smoothly on a $5/month VPS (1GB RAM) while still having Pull Requests, Issues, Wikis, and Kanban boards—just like GitHub.

Quick Deployment: Get Gitea Online in 5 Minutes with Docker Compose

Using Docker is the fastest way to manage your environment. If you need to upgrade your server later, you just move the folder, and you’re done. Below is the configuration file I’ve fine-tuned for a stable production environment.

version: "3"

networks:
  gitea:
    external: false

services:
  server:
    image: gitea/gitea:1.21.7
    container_name: gitea
    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__PASSWD=gitea_password
    restart: always
    networks:
      - gitea
    volumes:
      - ./data:/data
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "2222:22"
    depends_on:
      - db

  db:
    image: postgres:15-alpine
    restart: always
    environment:
      - POSTGRES_USER=gitea
      - POSTGRES_PASSWORD=gitea_password
      - POSTGRES_DB=gitea
    networks:
      - gitea
    volumes:
      - ./postgres:/var/lib/postgresql/data

The rest is simple. Save the file as docker-compose.yml and run the command:

docker-compose up -d

Now, open your browser and visit http://SERVER-IP:3000. The intuitive installation interface will appear immediately.

Standard Configuration for Real-World Projects

1. Choose Your Database: PostgreSQL is a Must

Using it for personal use to store a few scripts? SQLite works fine. However, if you’re working on a serious project or for a team, go with PostgreSQL. It helps Gitea handle concurrent operations more stably and provides better peace of mind for data backups.

2. Handling the SSH Port (Avoiding Host Conflicts)

The default port 22 is often occupied for logging into the server. In the configuration file above, I mapped port 2222:22. When cloning code, your SSH link will look like this: ssh://[email protected]:2222/user/repo.git.

Pro tip: During the initial web installation step, fill in the correct SSH_DOMAIN and SSH_PORT=2222 so Gitea automatically generates the correct clone links for your team to copy.

Masking Port 3000 with Nginx and SSL

Using port 3000 looks unprofessional and is less secure. I always use Nginx as a reverse proxy and install a free SSL certificate from Let’s Encrypt. Here is the configuration template:

server {
    listen 80;
    server_name git.yourdomain.com;

    location / {
        proxy_pass http://localhost: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;
    }
}

Just run certbot --nginx, and the system will automatically issue an HTTPS certificate. Your repository is now ready at https://git.yourdomain.com.

Automation with Gitea Actions (CI/CD)

Gitea Actions uses the exact same YAML syntax as GitHub Actions, so you won’t have to spend time relearning it. Instead of installing a heavy Jenkins setup, you just need a lightweight gitea-runner to automatically build Docker images and deploy every time code is merged into the main branch.

“Hard-Learned” Lessons from Experience

Never Trust Your VPS Hard Drive

I once lost two days of coding because the VPS hard drive suddenly failed without a recent backup. Since then, I’ve always run a cron job to dump data nightly. Here’s a quick backup command you can use in Docker:

docker exec -u 1000 gitea /app/gitea/gitea dump -c /data/gitea/conf/app.ini

The generated ZIP file contains all your code, database, and configuration. Push this file to another server or S3 so you can sleep soundly.

Saving the Day with Branch Protection

Have you ever had your heart skip a beat because a colleague “accidentally” git push --force-d over the main branch? Go to Settings -> Branches -> Add Rule for the main branch immediately. Disable force pushes and require a Pull Request to merge. A small action, but it will save you from unnecessary disasters.

Gitea is truly the best value investment for small teams who want to own their source code without monthly fees. I hope these insights help you feel more confident in building your own code “warehouse.”

Share: