What You’ll Need

  • A server or virtual machine running Linux (Ubuntu 20.04+ recommended).
  • At least 2 GB RAM, 2 CPUs, and 10 GB of storage.
  • Docker installed (or a standalone binary setup).
  • SSH access to the server.

Step 1: Install Docker (If Not Installed)

  1. Update the system
 sudo apt update && sudo apt upgrade -y
  1. Install Docker
 sudo apt install docker.io -y
 sudo systemctl enable --now docker
  1. Verify the installation
 docker --version

Step 2: Deploy Gitea with Docker

  1. Create a directory for Gitea data
 mkdir -p ~/gitea/{data,config}
  1. Run the Gitea container
 docker run -d --name gitea \
   -p 3000:3000 -p 2222:22 \
   -v ~/gitea/data:/data \
   --restart always \
   gitea/gitea:latest
  1. Check if the container is running
 docker ps

Step 3: Configure Gitea

  1. Access the web interface
    Open your browser and go to:
http://<your_server_ip>:3000
  1. Set up the database
  • Choose SQLite for a simple setup (or configure MySQL/PostgreSQL).
  • Configure the repository root directory: /data/gitea-repositories.
  • Set the SSH port to 2222 (or leave default if using another port).
  1. Create an Admin Account
  • Enter the first admin user details.
  • Complete the setup and restart Gitea.

Step 4: Create a Repository

  1. Log in to Gitea
  • Navigate to Repositories > New Repository.
  • Enter a repository name and select visibility.
  • Click Create Repository.
  1. Push Code to Your New Repo
git clone ssh://git@<your_server_ip>:2222/user/repository.git
cd repository
echo "# My Self-Hosted Git Repo" > README.md
git add .
git commit -m "Initial commit"
git push origin main

Step 5: Enable HTTPS with a Reverse Proxy (Optional)

To secure Gitea with HTTPS, you can use Nginx as a reverse proxy.

  1. Install Nginx
sudo apt install nginx -y
  1. Create a configuration file
sudo nano /etc/nginx/sites-available/gitea

Add the following content:

server {
  listen 80;
  server_name git.example.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;
  }
}
  1. Enable the configuration
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
sudo systemctl restart nginx
:::

1. **Use Let’s Encrypt for Free SSL (Optional)**  
:::bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d git.example.com

Step 6: Backup and Maintain Gitea

  1. Backup Gitea Data
tar -czvf gitea-backup.tar.gz ~/gitea
  1. Update Gitea
docker pull gitea/gitea:latest
docker stop gitea
docker rm gitea
docker run -d --name gitea \
-p 3000:3000 -p 2222:22 \
-v ~/gitea/data:/data \
--restart always \
gitea/gitea:latest
  1. Monitor Logs
docker logs -f gitea

FAQs

Q: Why use Gitea instead of GitHub or GitLab?
A: Gitea is lightweight, fast, and lets you fully own your repositories without relying on third-party services.

Q: Can I use Gitea without Docker?
A: Yes! You can install the standalone binary or use package managers like apt or yum.

Q: How do I add SSH keys to Gitea?
A: Go to Settings > SSH Keys, and add your public key.

Q: Can I migrate repositories from GitHub?
A: Yes, Gitea includes an import tool to migrate repositories directly.

Q: How do I enable email notifications?
A: Configure SMTP settings under Admin Panel > Configuration.


By hosting your own Git server with Gitea, you gain full control over your repositories while keeping your workflow efficient. Try it out and build your private version control system!