A self-hosted Git server keeps your repositories, issues and commit history on a machine you control, instead of on GitHub or another company's platform. Git itself needs almost nothing to host. The real choice is how much web software you want around it, and that decides how big a server you need. This guide compares the four realistic options, explains what self-hosting does and does not change, and walks through setting up Forgejo on a small VPS.
The short version
For most people, run Forgejo on a small VPS behind HTTPS. It gives you a GitHub-style web interface with issues and pull requests, and it is light enough for an entry-level VPS. If you only need somewhere to push code, plain Git over SSH needs no extra software at all. GitLab does far more, but its own documentation sets 8 GB of RAM as the floor, so it needs a large VPS or a dedicated server. If you would rather not run a server, Codeberg hosts Forgejo for free and open-source projects.
Why run a self-hosted Git server
Most developers never think about where their code lives until a platform decides for them. Two cases show how it happens:
- Sanctions. In July 2019, GitHub restricted private repositories and paid accounts for developers in Iran, Syria and Crimea to comply with US trade sanctions. Public repositories stayed available, and GitHub restored full access in Iran in 2021 after securing a US government license.
- Takedowns. In October 2020, GitHub removed youtube-dl after the RIAA sent a notice under the US DMCA. The project came back in November, once the Electronic Frontier Foundation answered the claim on its behalf.
A self-hosted Git server takes the platform's own rules out of the picture, but not the law. A takedown notice or court order then goes to your hosting provider instead, under the rules of the country where the server sits. Our guide to DMCA takedowns and hosting jurisdiction explains how that differs between countries.
The other reasons are quieter. Private repositories, issue discussions and the record of who pushed what and when stay on your own server. No code platform can lock the account your work depends on, and the software only changes when you update it. The trade-offs are real too: you lose GitHub's audience for public projects and its free CI minutes, and uptime, updates and backups become your job. Many people run both, keeping public projects on GitHub and private work on their own server.
Four self-hosted GitHub alternatives
Plain Git over SSH No web interface
Any server you can reach over SSH is already a basic self-hosted Git server. Create a bare repository with git init --bare and clone it with git clone [email protected]:/srv/git/project.git, as the Pro Git book describes. There is nothing extra to run or update, but there is also no web interface, no issues and no pull requests. It suits one person who wants a private place to push code, or a backup copy of repositories that live elsewhere.
Forgejo Our pick
A complete forge with repositories, issues, pull requests, a wiki, package registries and its own CI system, Forgejo Actions. It began in December 2022 as a fork of Gitea, after Gitea's trademarks moved to a for-profit company, and became a fully separate project in February 2024. It is developed under the umbrella of Codeberg e.V., a non-profit, and has been licensed under the GPL since version 9. One long-term support release comes out each year: Forgejo 15 is supported until 15 July 2027. Its own site says it can run on an inexpensive Raspberry Pi.
Gitea Company-backed
The project Forgejo came from, still MIT-licensed and very similar to use. Gitea's documentation says a Raspberry Pi 3 is enough for small workloads, and that 2 CPU cores with 1 GB of RAM is typically enough for small teams. The difference from Forgejo is mostly who runs it: Gitea's trademarks belong to Gitea Ltd, a company that also sells commercial services around it. Both are good software. We pick Forgejo for its non-profit governance and its long-term support releases.
GitLab Community Edition Needs a big server
A full development platform with mature CI pipelines, a container registry and much more. That scope has a cost. GitLab's installation requirements give 8 vCPU and 16 GB of RAM as the baseline for a single-node install, at least 8 GB for a memory-constrained setup, and at least 40 GB of disk before you add any repositories. Pick it if your team needs those features, and plan for a large VPS or a dedicated server rather than an entry-level plan.
A self-hosted Git server compared
| ย | Plain Git over SSH | Forgejo | Gitea | GitLab CE |
|---|---|---|---|---|
| Web interface | No | Yes | Yes | Yes |
| Issues and pull requests | No | Yes | Yes | Yes |
| Memory | Nothing beyond SSH | Low; runs on a Raspberry Pi | 1 GB for small teams | 16 GB baseline, 8 GB minimum |
| License | GPLv2 (Git) | GPLv3 or later | MIT | MIT |
| Run by | You | Community, under Codeberg e.V. | Gitea Ltd | GitLab Inc. |
Memory figures are the projects' own: Gitea and GitLab publish them, and Forgejo publishes none beyond its Raspberry Pi claim. Treat them as a floor, and add more if you run CI jobs on the same machine.
Set up Forgejo on a VPS
This setup runs your self-hosted Git server as two Docker containers: Forgejo, and the Caddy web server in front of it. Caddy fetches and renews the HTTPS certificate on its own. It is the same pattern as our self-hosted password manager guide. Before you start, you need:
- A Debian or Ubuntu VPS, secured as described in our VPS security checklist.
- Docker Engine and the Docker Compose plugin, installed from Docker's own repository as Docker's installation guide describes.
- A domain or subdomain, here
git.example.com, with an A record pointing to your server's IP address.
1. Create the folder and the compose file
mkdir -p ~/forgejo/forgejo
sudo chown 1000:1000 ~/forgejo/forgejo
cd ~/forgejo
nano docker-compose.yml
Paste this in, replace git.example.com with your own domain in all three places, and save:
services:
forgejo:
image: codeberg.org/forgejo/forgejo:15
container_name: forgejo
restart: always
environment:
- USER_UID=1000
- USER_GID=1000
- FORGEJO__server__DOMAIN=git.example.com
- FORGEJO__server__SSH_DOMAIN=git.example.com
- FORGEJO__server__ROOT_URL=https://git.example.com/
- FORGEJO__server__SSH_PORT=222
- FORGEJO__service__DISABLE_REGISTRATION=true
- FORGEJO__service__REQUIRE_SIGNIN_VIEW=true
- FORGEJO__repository__DEFAULT_PRIVATE=private
volumes:
- ./forgejo:/data
- /etc/localtime:/etc/localtime:ro
ports:
- "222:22"
caddy:
image: caddy:2
container_name: caddy
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./caddy-data:/data
- ./caddy-config:/config
The 15 tag follows Forgejo's long-term support release and picks up its bug and security fixes when you update. Git over SSH uses port 222 so it does not clash with your own SSH login on port 22, and SSH_PORT=222 makes Forgejo show that port in its clone URLs.
The last three environment lines keep the server private. Registration is switched off, so strangers cannot sign up. REQUIRE_SIGNIN_VIEW makes visitors log in before they can see any repository or user profile, and DEFAULT_PRIVATE makes every new repository private unless you untick the box. If you also want to share public projects from this server, change true to false on the REQUIRE_SIGNIN_VIEW line and run sudo docker compose up -d again.
2. Point Caddy at Forgejo
nano Caddyfile
Put this in, with your own domain, and save:
git.example.com {
reverse_proxy forgejo:3000
}
Forgejo's web port, 3000, is not published at all. Only Caddy can reach it, over Docker's internal network. That matters because Docker opens published ports itself, even when ufw is switched on, so the compose file publishes only the three ports that should be public: 80, 443 and 222. If your provider runs a firewall in front of the server, open those three ports there as well.
3. Start it and finish the setup straight away
sudo docker compose up -d
Open https://git.example.com right away. Forgejo shows its initial configuration page. Leave the database on SQLite, which Forgejo uses by default and which is fine for personal use and small teams. Check that the domain, the SSH port (222) and the base URL match your settings. Then open Administrator account settings and create your account there, since registration is off and nobody can sign up later. Finish the installation and log in.
sudo docker compose down and sudo rm -rf ~/forgejo/forgejo, run the first two commands from step 1 again, and start the containers.4. Turn on two-factor authentication and add your SSH key
In Forgejo, open Settings, then Security, and enroll in two-factor authentication. This account controls the whole server, so a stolen password alone should not be enough to get in. Then open SSH / GPG keys, add the public key from your computer, and test the connection:
ssh -p 222 [email protected]
Forgejo should reply that you have authenticated and then close the connection, because it does not offer a shell. Every repository page shows its clone URL, in the form ssh://[email protected]:222/alice/project.git.
5. Bring your repositories over
Choose New migration from the + menu to import a repository from GitHub, GitLab or another forge. With an access token from the old platform, the import can bring issues, pull requests, releases and the wiki along with the code. You can also set up a mirror, which keeps a copy in sync, if you want to keep working on GitHub while your own server holds a copy.
6. Back it up and keep it updated
Everything your self-hosted Git server needs sits in the ~/forgejo folder: the compose file, the Caddyfile, Caddy's certificates and Forgejo's own data, including the repositories, the SQLite database and the configuration. Stopping Forgejo for a moment gives you a clean copy of all of it:
cd ~/forgejo
sudo docker compose stop forgejo
sudo tar czf ~/forgejo-backup-$(date +%F).tar.gz -C ~ forgejo
sudo docker compose start forgejo
Copy the file off the server, for example with scp from your own computer, and keep it somewhere private, since it holds your code and the server's keys. A backup kept on the same VPS disappears with it.
To restore a backup on the same server, for example after a failed upgrade, stop the containers, move the current folder aside, unpack the backup and start again:
sudo docker compose -f ~/forgejo/docker-compose.yml down
mv ~/forgejo ~/forgejo-old
sudo tar xzf ~/forgejo-backup-2026-11-27.tar.gz -C ~
cd ~/forgejo
sudo docker compose up -d
Use your own backup's file name. To move your self-hosted Git server to a new machine, install Docker there, copy the backup into your home folder, run the last three lines, and point your domain's A record at the new IP address.
To install the latest fixes for your release:
sudo docker compose pull && sudo docker compose up -d
Moving to a new major version is a separate step, and Forgejo's documentation says it needs manual work and checking. The next long-term support release, Forgejo 19, is due on 15 April 2027. Read its release notes and take a backup before you change the tag.
Forgejo Actions, the built-in CI, is optional. Its jobs run on a separate program, Forgejo Runner, which can use far more CPU and memory than Forgejo itself. Run it on a larger plan or a second server rather than squeezing it onto the smallest one.
Running it on Packetra
For a self-hosted Git server running Forgejo, our smallest anonymous VPS is enough for personal use or a small team, with 2 vCPU, 1.5 GB of RAM and 25 GB of disk, from EUR 9.90 a month in Finland and EUR 13.90 in Switzerland. Move up a plan for more disk or for a CI runner. Each VPS is a full KVM virtual machine with its own kernel, so Docker works as it would on your own hardware. GitLab needs more memory than our largest VPS has, so for GitLab look at our dedicated servers, which start at EUR 163.90 a month with 64 GB of RAM. Signup takes an email address and a password, and you can pay in Bitcoin or Monero through our own BTCPay Server. To choose between the two countries, see Finland vs Switzerland for hosting.
Self-hosted Git server FAQ
Is Forgejo the same as Gitea?
Not any more. They share most of their code from before 2024, so they look and work alike, but Forgejo has been a separate project since February 2024 and the two keep drifting apart. Forgejo is GPL-licensed and run by a non-profit community; Gitea is MIT-licensed and backed by a company.
Can I keep using GitHub as well?
Yes. A self-hosted Git server can push a mirror of any repository to GitHub, so you work on your own server and GitHub gets a copy. You can also do the reverse and keep a pulled mirror of GitHub projects on your own server as a backup.
Do I need PostgreSQL?
Not for personal use or a small team. Forgejo uses SQLite unless you configure another database, and SQLite keeps everything in one file that the backup above already covers. Move to PostgreSQL if many people use the server at once.
Is a self-hosted Git server private?
Private repositories are visible only to the accounts you allow, and with the settings in the setup above, visitors who are not logged in cannot browse repositories or user profiles at all. Nothing is shared with a code platform. Commits carry their own details, though: each one records the author name and email address from your Git settings and a timestamp with your time zone, and anyone who can read the repository can see them. They are baked into each commit, so set the name and address you want with git config before you start. The server is still a computer in someone's data centre, so the host's policies and country matter. Our guide to whether your hosting provider can see your data explains what a host can and cannot reach.
What if I would rather not run a server?
Codeberg, run by the non-profit Codeberg e.V. in Berlin, hosts Forgejo for free and open-source projects. It is a good home for public work if you want to leave GitHub without maintaining anything yourself.
Sources
- Forgejo documentation: Installation with Docker (image tags, environment variables, SQLite default, major upgrades)
- Forgejo documentation: Configuration cheat sheet (REQUIRE_SIGNIN_VIEW, DEFAULT_PRIVATE)
- Forgejo: v17.0 release announcement (release and support schedule)
- Forgejo: Forgejo forks its own path forward (hard fork, February 2024)
- Forgejo: Forgejo is now copyleft (GPL license change)
- Gitea documentation: What is Gitea? (system requirements)
- GitLab documentation: Installation requirements
- Pro Git: Git on the Server, Setting Up the Server
- Pro Git: First-Time Git Setup (name and email in every commit)
- Git documentation: git-commit (commit dates and time zone offset)
- Certificate Transparency: How CT works (public certificate logs)
- GeekWire: GitHub restricts accounts in countries facing US sanctions (July 2019)
- GitHub Blog: GitHub is fully available in Iran (January 2021)
- EFF: GitHub reinstates youtube-dl after RIAA's abuse of the DMCA (November 2020)
- Codeberg documentation: What is Codeberg?
Last reviewed: 27 November 2026
Research note: Version numbers, support dates and hardware figures come from each project's own documentation and release announcements as of the review date, and they change with every release. The setup is a starting point for a personal or small-team server; read Forgejo's documentation before running it for a larger group.
Shared Hosting
WordPress Hosting
VPS Hosting
Dedicated Servers