How to start your own epic Git server!
Date: 23-02-2025
Quick guide on how to set up a git server with stagic html website.
What you will need 📋
- A computer with Linux 🐧🖥️
- A VPS with Linux instaled 🐧🗄️
- Some terminal knowlage 🧠
- Ideally have a domain name
Setting up Git server
# sudo apt install git
# sudo adduser git
On server
# su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
On computer
$ cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCyXwuFdbWHloGPOfFq6p5Dt..... me@shipwreckt.co.uk
Copy and paste your ssh key to .ssh/authorized_keys on your server.
If you want to allow other people to use your Git server, add their SSH keys alongside yours.
# chown git:git /srv/git
# su git
$ cd /srv/git
$ mkdir yourrepo.git
$ cd yourrepo.git
$ git init --bare
On computer
$ cd yourrepo
$ git init
$ git add .
$ git commit -m 'Initial commit'
$ git remote add origin git@gitserver:/srv/git/project.git
$ git push origin master
If you already have a Git repository from another server, you can do the following to add your new Git server alongside your old one.
On computer
$ cd yourrepo
$ git remote add server git@gitserver:/srv/git/project.git
$ git push server master && git push origin master
You can now do this for all of your repos!
# sudo git daemon --reuseaddr --base-path=/srv/git/ /srv/git/ &
# sudo systemctl enable git-daemon
# sudo systemctl start git-daemon
# su git
touch /srv/git/project.git/git-daemon-export-ok
Cloning your git repo
On computer
git clone git://your-server-ip-address/repository.git
Now you should be able to be able to clone without a ssh key!
Setting up Stagit for personal git website
Now that you have a Git server, you probably want a way to show off all of your repositories. I personally use Stagit for this because it is lightweight and stylish. I will assume you know how to make a website using Apache or Nginx.
# cd /var/www
# git clone git://shipwreckt.co.uk/stagit-fork.git
# mkdir git
# chown git:git git
# mv stagit-fork/* git
# cd git
# sudo make clean install
# cd htmldir
# sh example_create.sh
Your static stagit website should be generated for you! Check by going to git.yourdomain.com.
Descriptions
# This is my git repo > /srv/git/yourrepo.git/description
URL
# git://yourdomain.com/yourrepo.git > /srv/git/yourrepo.git/url
Owner
# owner > /srv/git/yourrepo.git/owner
Update stagit
# sh /var/www/git/htmldir/example_create.sh
Now repete for all of your repos till all is correct!
Now whenever you push a commit everything should update!
Overview
I hope this guide has helped you setup a kool git server! If there are any problems please contact me!
Back 🚪