Sometimes, it’s just easier and safer to keep things in your own hands. That’s why I started hosting my own Git server at home. Git is a version control system, which means it helps you keep track of changes to your code, documents, or any files over time. It’s what programmers use to manage their projects. And it’s free.
A self-hosted Git server is a Git server you run by yourself, usually on your own computer or a server you rent. That way, you don’t need GitHub, GitLab, or other cloud services. You control everything. It’s private, customizable, and great for learning.
Let me show you how I did it. It’s not hard, but it does take a bit of setup.
Why Host Your Own Git Server?
Before we get into the steps, let me explain why I chose to go this route.
I work on small personal projects. Sometimes, they’re just ideas I’m testing out. I didn’t want to share them with the world yet. I also didn’t want to rely on a cloud service that could go offline or suddenly change its terms.
When I host my own Git server:
- I control who can see and change my projects.
- I don’t need an internet connection to push or pull if I’m working on a local network.
- I learn more about how Git and servers work, which helps me grow as a developer.
Also, if you’re working on school assignments, personal notes, or small websites, a self-hosted Git server is a nice tool to have.
What You Need
You don’t need fancy hardware to run a Git server. Here’s what I used:
- A Linux server (can be an old laptop or a VPS). I used Ubuntu Server.
- SSH (Secure Shell) set up and working.
- Git installed on both your local computer and the server.
If you’re not using Linux, it’s still possible, but I recommend Linux because it’s simple and well-documented. Plus, it’s what I’m used to.
Setting It Up Step by Step
Here’s how I set up my self-hosted Git server. I’ll walk you through each step, just like I did it.
1. Install Git on Your Server
First, I logged into my Ubuntu server.
sudo apt update
sudo apt install git
That’s it. Now the server can understand Git commands.
2. Create a Git User
Instead of using your main user for Git, it’s safer to make a new one. I made a user named git
.
sudo adduser git
You’ll be asked to set a password and some details. You can skip the details by just pressing Enter.
This user will manage all your Git repositories.
3. Set Up SSH Access
This part makes sure you can connect to your Git server safely.
On your local computer (the one you write code on), make sure you have an SSH key:
ssh-keygen
Press Enter to accept defaults. Then, copy the key to your server:
ssh-copy-id git@your-server-ip
Now, when you type ssh git@your-server-ip
, you’ll log in without a password. You’ll need this to push and pull code.
4. Create a Repository
I created a new folder on the server to store my Git repositories:
sudo mkdir -p /home/git/repos
sudo chown git:git /home/git/repos
Now, let’s create a repository. Still on the server:
cd /home/git/repos
sudo -u git git init --bare myproject.git
A bare repository is one without a working copy. It’s only used for pushing and pulling code, not editing.
5. Clone the Repository From Your Computer
Back on your computer, you can now clone your new Git repository:
git clone git@your-server-ip:/home/git/repos/myproject.git
You now have a working copy. Make changes, commit them, and push them back to the server:
git add .
git commit -m "First commit"
git push
And it works just like GitHub. Only this time, it’s all yours.
Some Tips and Gotchas
When I first set this up, I ran into a few issues. Here are some things that helped:
- Make sure your server has a static IP or use a dynamic DNS service like DuckDNS.
- Always use SSH keys. They’re safer and easier once set up.
- Use
chmod
carefully. I once broke my repo by changing permissions the wrong way.
If you want others to access your Git server, just add their SSH public keys to /home/git/.ssh/authorized_keys
.
Want a Nicer Interface?
This basic setup works great. But if you want a web interface (like GitHub), there are free tools like:
- Gitea – lightweight and fast, I used this once for a project with friends.
- GitLab CE – big and full-featured, better for teams.
- SourceHut – minimal and simple, for advanced users.
These give you a GUI, issues tracking, and more. But they take more memory and setup time.
I stuck with the basic method because it’s light and fast. You might like it too.
When to Use Self-Hosting vs GitHub?
Here’s a quick comparison from my experience:
Feature | GitHub | Self-Hosted |
---|---|---|
Easy setup | ✅ | ❌ (takes time) |
Private by default | ❌ | ✅ |
Full control | ❌ | ✅ |
Extra features | ✅ | ❌ (unless you install them) |
Works offline | ❌ | ✅ (local network only) |
If you’re just starting out, GitHub is great. But if you’re curious, like privacy, or just want to learn, try self-hosting.
Summary: What You Get
By setting up your own Git server, you:
- Learn how Git works behind the scenes
- Gain control over your files and who accesses them
- Avoid monthly fees or restrictions from cloud services
Here’s what I like most:
- No need for internet when working at home
- No limits on private repositories
- I understand Git better now
If you’re someone who likes to tinker and learn, I think you’ll enjoy doing this.
Handy Commands Recap
Just to help you remember:
- Install Git:
sudo apt install git
- Add Git user:
sudo adduser git
- Make SSH key:
ssh-keygen
- Copy key:
ssh-copy-id git@server
- Make repo:
git init --bare
- Clone:
git clone git@server:path
- Push:
git push
Final Thoughts
Hosting my own Git server taught me a lot. It also gave me freedom. No ads, no limits, and I didn’t have to sign up for anything.
Sure, it’s not for everyone. If you’re just sharing code with others online, GitHub is easier. But if you want to learn more, protect your code, or run a private project, it’s worth trying.
Would you try hosting your own Git server? Or do you think cloud services are enough for you?