Gitolite: Ultra-lightweight Git Server Management for 1GB RAM VPS

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

When GitLab is a “Burden” for Low-Spec VPS

Running an outsource project on a tight budget? A tiny VPS with 1 vCPU and 1GB RAM will definitely “cry for help” if you try to cram GitLab into it. Even Gitea – while known for being lightweight – still consumes resources for its web interface and database.

I once found myself in a tough spot: a client required absolute code security on their aging Ubuntu server. No GitHub, no Bitbucket. That’s when Gitolite came to the rescue. It’s an access control layer running on top of SSH, similar to a self-hosted Git bare repository but with much more granular control. It has no fancy UI; everything operates via the command line and text files, but in return, it’s incredibly stable.

While GitLab needs at least 2-4GB of RAM to run smoothly, Gitolite consumes almost zero RAM when idle. The biggest selling point is the ability to manage permissions down to specific branches or tags. You manage the entire Git server by… pushing code to a special repository named gitolite-admin.

Deploying Gitolite on the Server

To get started, you need a Linux server (Ubuntu/Debian) with Git installed and a local machine to act as the Admin.

Step 1: Initialize the Git User

Create a dedicated user to isolate the repositories. Never use the root user to run Gitolite to ensure system security.

# Update and install Git
sudo apt update && sudo apt install git -y

# Create a secure 'git' user without a password
sudo adduser --system --shell /bin/bash --group git

Step 2: Configure SSH Key for the Admin

On your local machine, check your SSH Key. If you don’t have one, generate a new 4096-bit key pair:

ssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa_gitadmin

Next, upload the public key file to the server’s temporary directory using scp:

scp ~/.ssh/id_rsa_gitadmin.pub user@your-server-ip:/tmp/admin.pub

Step 3: Install from Source

Now, switch to the git user on the server to proceed with the setup. I recommend installing from source to get the latest version.

# Switch to git user
sudo su - git

# Clone source code and install
git clone https://github.com/sitaramc/gitolite
mkdir -p ~/bin
./gitolite/install -to ~/bin

# Initialize Gitolite with the prepared Admin key
~/bin/gitolite setup -pk /tmp/admin.pub

The system will automatically create the repositories/ directory. Inside, you’ll find two default repos: gitolite-admin.git (for configuration) and testing.git.

Managing in Infrastructure as Code Style

With Gitolite, you don’t need to SSH into the server every time you want to create a new repo. All changes are made directly from your local machine.

1. Clone the Admin Repo

For a smooth workflow, add the configuration to your ~/.ssh/config file on your local machine:

Host git-server
    HostName your-server-ip
    User git
    IdentityFile ~/.ssh/id_rsa_gitadmin

Now, clone the admin repo to your machine:

git clone git-server:gitolite-admin
cd gitolite-admin

2. Adding Teammates to the Project

Suppose you need to add huy-dev to the team. Get Huy’s id_rsa.pub file, place it in the keydir/ directory, and rename it to huy-dev.pub. The filename becomes the username within the Gitolite system.

3. Permissions and Repo Creation

Open the conf/gitolite.conf file. This is where the magic happens:

repo secret-project
    RW+     =   admin
    RW      =   huy-dev
    R       =   @all

Meaning of basic permissions:

  • RW+: Full permissions (including force push and branch deletion).
  • RW: Standard Push/Pull permissions.
  • R: Read-only access.
  • @all: Applies to every user with a key in the system.

Once you’re done editing, just commit and push:

git add .
git commit -m "Add huy-dev and secret-project repository"
git push origin master

Immediately, Gitolite will initialize the secret-project.git repository on the server. Huy can start working right away.

Advanced Feature: Branch Protection

In practice, you usually don’t want developers pushing directly to the master branch. While platforms like GitHub have GUI-based branch protection rules, Gitolite handles this elegantly using Regex:

repo secret-project
    RW+ master      =   admin
    RW  develop     =   huy-dev
    RW  feature/.*  =   huy-dev

This configuration forces huy-dev to work on develop or feature/ branches. If Huy accidentally pushes to master, the server will reject it immediately with an error message.

Hard-earned Lessons from Operation

Accidentally mistyped the config syntax? Don’t worry, Gitolite will block you at the time of pushing. This is because it relies on Git server hooks to validate permissions. However, if there’s a system issue, check the logs at /home/git/.gitolite/logs/. Logs are organized by date, making it easy to trace who did what.

One important note: Never edit files directly inside the .gitolite directory on the server. Always perform changes via the gitolite-admin repository. If you lose your admin SSH key, you’ll be forced to use root privileges on the server to re-run the setup command and load a new key.

Gitolite might have a slight learning curve at first due to the lack of a web UI. But once you’re used to it, you’ll find it fast, secure, and extremely lightweight for low-spec VPS environments, especially when combined with regular Git maintenance to keep things snappy.

Share: