Linux & Servers guides, explanations and reader checklists on whilenetworking.com

How to Set Up and Manage a Private Git Repository Server with Gitea or GitLab

Moving your codebase from public platforms like GitHub or GitLab.com to a private server is a critical step for organizations concerned about data…

Moving your codebase from public platforms like GitHub or GitLab.com to a private server is a critical step for organizations concerned about data sovereignty, security compliance, and cost management. Whether you are a small development team looking for a self-hosted solution or an enterprise needing full control over access policies, setting up a private Git repository server is achievable with the right tools. The two most popular open-source options are Gitea and GitLab. Gitea is renowned for its lightweight footprint, making it ideal for low-resource environments, while GitLab offers a feature-rich, all-in-one DevOps platform comparable to the commercial versions of GitHub. This guide provides a practical, step-by-step approach to installing, configuring, and managing these platforms securely.

Choosing Between Gitea and GitLab

Before writing a single line of configuration code, you must decide which tool aligns with your infrastructure needs. Gitea is written in Go and compiles into a single binary. It typically consumes less than 100MB of RAM at rest and scales well on modest hardware. If your primary goal is simply to host Git repositories, manage issues, and handle pull requests without the overhead of complex CI/CD pipelines or extensive UI customization, Gitea is often the superior choice.

GitLab, conversely, is a Ruby-based monolithic application (with components in Go and Node.js) that includes built-in continuous integration/continuous deployment (CI/CD), container registries, and advanced security scanning. However, this power comes with resource requirements; a production-ready GitLab instance often requires at least 4GB of RAM and significant disk I/O optimization. If you need an integrated DevOps ecosystem rather than just a repository host, GitLab is the industry standard for private hosting.

Prerequisites and Server Preparation

Regardless of your choice, both applications require a Linux server environment. While they can run on Windows or macOS via Docker, production deployments should ideally occur on Linux distributions like Ubuntu LTS or Debian. You will need:
* A server with at least 2 CPU cores and 2GB of RAM (4GB+ recommended for GitLab).
* Root access or sudo privileges.
* Domain name pointing to your server’s IP address (optional but recommended for HTTPS).
* PostgreSQL, MySQL, or SQLite as a database backend (SQLite is only suitable for Gitea in development; production requires a relational database).
* A reverse proxy like Nginx or Caddy for handling SSL termination.

Installing Gitea via Docker Compose

Docker is the most reliable method for managing dependencies, ensuring consistency across environments. To install Gitea, create a directory named gitea and download the official docker-compose.yml file. This single configuration file orchestrates the web server, database, and application container.

version: '3'
services:
  gitea:
    image: gitea/gitea:latest
    environment:
      - USER_UID=1000
      - USER_GID=1000
    volumes:
      - ./gitea-data:/data
    ports:
      - "3000:3000"
    networks:
      - gitea-network

  postgres:
    image: postgres:15-alpine
    environment:
      POSTGRES_USER: gitea
      POSTGRES_PASSWORD: password
      POSTGRES_DB: gitea
    volumes:
      - ./postgres-data:/var/lib/postgresql/data
    networks:
      - gitea-network

networks:
  gitea-network:
    driver: bridge

Once the file is saved, run docker-compose up -d. Access the setup wizard at http://your-domain.com:3000 (or port 80 if you configure Nginx later). During installation, create an administrator account and configure the database connection. Remember to change the default password immediately after logging in.

Installing GitLab on Ubuntu with APT

For GitLab, the official recommendation is to use the GitLab Omnibus package, which simplifies installation by bundling all necessary components. On a fresh Ubuntu server, update your package lists and add the GitLab GPG key:

curl -fsSL https://packages.gitlab.com/install/repositories/gitlab/gitlab.sh stable | bash

This script automatically handles dependencies, including PostgreSQL, Redis, and Nginx. It creates a gitlab-rails user and configures systemd services. After installation, access the web interface at http://your-domain. You will be prompted to configure your root password and set up initial database credentials. GitLab is significantly more complex to configure initially due to its vast array of features, but it provides a robust foundation for enterprise workflows out of the box.

Configuring Security and SSL Certificates

Security is paramount when hosting private repositories containing sensitive code. Both Gitea and GitLab support Let’s Encrypt via Certbot for automated HTTPS certificate management. Without SSL, your communication is vulnerable to man-in-the-middle attacks, and many modern browsers will flag the site as “Not Secure.”

For Gitea, ensure Nginx is configured as a reverse proxy before installing certificates. For GitLab, the Omnibus installer usually includes a script to integrate Certbot automatically when prompted during the initial setup or via gitlab-ctl reconfigure. Always enforce HSTS (HTTP Strict Transport Security) headers to prevent protocol downgrade attacks. Additionally, configure your firewall (such as UFW) to restrict inbound traffic to ports 80 and 443 only, blocking direct access to the application ports from the public internet if possible.

Managing Users, Groups, and Access Controls

Once installed, the administrative interface allows you to define granular access controls. Start by creating Groups that represent departments or projects (e.g., “Engineering,” “Marketing”). Then, add users and assign them to these groups. Most importantly, configure Webhooks and SSH keys.

For SSH access, generate an RSA key pair on your local machine:

ssh-keygen -t ed25519 -C "your_email@example.com"

Copy the public key (~/.ssh/id_ed25519.pub) to the server using ssh-copy-id. In Gitea, navigate to Admin -> Users -> [User Name] -> SSH Keys. In GitLab, go to User Settings -> Edit Profile -> SSH Keys. This allows developers to push code securely without exposing passwords. Always audit access logs regularly to detect unauthorized login attempts or suspicious repository cloning activity.

Real-World Deployment Checklist and Best Practices

Deploying a private git server is not a “set it and forget it” task. To ensure long-term stability, follow this checklist before going live:
1. Database Backups: Schedule automated daily backups of your PostgreSQL/MySQL database. Store these backups off-server in cloud storage (e.g., S3) to protect against ransomware or hardware failure.
2. Log Rotation: Configure log rotation for application and system logs to prevent disk space exhaustion. GitLab generates massive logs; Gitea is lighter but still requires monitoring.
3. Update Strategy: Plan a maintenance window to apply security patches. For Docker, update the base images periodically. For Omnibus GitLab, use gitlab-ctl reconfigure after updating packages, but be aware that major version upgrades may require data migration scripts.
4. Monitoring: Set up monitoring tools like Prometheus and Grafana to track CPU usage, memory consumption, and disk I/O. Alerting is crucial because a runaway process in the CI/CD pipeline can crash the entire server.
5. Disaster Recovery: Document your recovery procedures. Can you restore the database from backup? Do you have a way to migrate data if you switch hosting providers?

Conclusion

Setting up a private Git repository server empowers your team with full control over your intellectual property and development workflow. Gitea offers a lightweight, low-maintenance solution perfect for teams prioritizing simplicity and resource efficiency. GitLab provides a comprehensive DevOps suite ideal for organizations requiring integrated CI/CD pipelines and advanced security features. The decision ultimately depends on your hardware capabilities and feature requirements. By following the installation steps, securing your environment with SSL, and implementing rigorous backup and monitoring strategies, you can build a resilient private repository infrastructure that supports your development lifecycle effectively.