SabaKore

Home / Articles / Use cases

Setting Up Your Own Git Server on a VPS

Why you might host it yourself instead of using a ready-made service, and the specs you need. This article covers how storage grows, the load when you also run automation, and keys and access control.

Ren, a junior infrastructure engineer

Ren

I'd like to host my code on my own VPS. What's it actually like?
Procura, a cloud AI robot who explains

Procura

It's a light kind of use, so it runs even on a smaller plan. If a ready-made service is working for you, there's no need to force a move, but if you have a reason to host it yourself, it's a realistic choice.

Reasons to host it yourself

  • You have circumstances that prevent you from putting code on an external service
  • You want to create private repositories without worrying about how many
  • You already rent a VPS with room to spare
  • You want to learn operations itself
Procura, a cloud AI robot who explains

Procura

On the other hand, if the ready-made service isn't causing you trouble, I think you can leave it as is. Large services can't be beaten on availability (being able to keep using it without it going down) or on features.

Specs you need

  • If it's just for browsing and storing repositories, a smaller plan works
  • A setup that also uses a database is typical
  • Storage grows more from history than from the code itself
  • If you handle large files, the capacity estimate changes
Procura, a cloud AI robot who explains

Procura

The third one is a blind spot. Even if the code is light, the history of changes piles up. After running it for years, it can be bigger than you'd imagine.

When you also run automation

Procura, a cloud AI robot who explains

Procura

Just storing code is light, but once you add a mechanism that runs tests and builds on every change, it's a different story. That becomes the part that uses the most resources.
  • Running builds uses a lot of both CPU and memory
  • If you run them on the same server, even browsing becomes slow
  • There are also setups that run them on a separate server
  • On a small plan, a build can fail from running out of memory

How to restrict access

Source code usually doesn't need to be public. If you keep it off the internet and limit access to behind a VPN or to specific IP addresses, the effort of protecting it drops a lot. It's more reliable not to let people reach it at all than to put it somewhere anyone can reach and then work hard to protect it.

Wilson, the security guard

Wilson

...Credentials often end up mixed into code. That's why I like Git servers.
  • Don't leave it public with sign-ups open to anyone
  • Use key-based authentication for SSH connections
  • Use a strong password for the control panel, and turn on two-factor authentication if available
  • There's also a setup that isn't exposed outside at all and is used only through a VPN

Combine it with ready-made services

Procura, a cloud AI robot who explains

Procura

You don't have to move everything to your own server. Often a realistic split is to keep things you want to make public on a ready-made service and host only the things you can't put outside yourself.
  • Public projects: a ready-made service (easier for people to find)
  • Private projects: self-hosting is fine
  • If your own server goes down, the public projects aren't affected
  • Copies also remain on your own machine, which is Git's advantage. Losing everything is unlikely
Procura, a cloud AI robot who explains

Procura

The fourth is reassurance specific to this use. History also remains on each person's own machine, so it's easy to recover even if the server goes down. Even so, take backups separately.
Ren, a junior infrastructure engineer

Ren

Just storing code is light, but once you add builds it's a different thing.

This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.