Sign in
Log inSign up
How I created my own git server 👨🏽‍💻 and how can you too!

How I created my own git server 👨🏽‍💻 and how can you too!

Learn how to create your own git server and host it on your LAN network 🚀

HARSH BAJPAI's photo
HARSH BAJPAI
·Mar 9, 2021·

5 min read

Okay, so a one-liner on why I decided to host my own git server...

because I was bored and I needed to do something cool and fun 🚀

yeah! hosting my own git server on a LAN was a very cool idea for me so I went with it.

giph

So here I am sharing a detailed walkthrough of how I did it and how can you too (:

What do you need?

So, I have used a Raspberry pi 4 as the git server. I can keep it running 24*7 which makes it a perfect choice as a git server.

image.png

You can use a Raspberry pi 3 or any machine running Linux 🙌🏾

1. SSH into your Raspberry Pi

So, SSH into your raspberry pi via your terminal. You have to enable SSH into your raspberry pi. There are plenty of videos on youtube on how to do that.

Your default username is pi and the password will be raspberry. ( if you haven't manually changed it )

Go to your terminal and type the following command:

ssh pi@raspberry_pi_address

raspberry_pi_address is the local IP address of your pi which has been given to it by your router.

This command won't work for Windows users ( you have to install putty for doing that ).

windows meme

After that, it will ask for a password which by default is raspberry. That's it you are in (:

2. Installing Gitlab

Yes, so now we will install Gitlab on pi and use it to host our Git repositories.

image.png

Now, before you move forward with the next steps make sure that your pi is up-to-date and is using the latest packages.

Now go to the terminal and perform the following command:

sudo apt-get install curl openssh-server ca-certificates postfix apt-transport-https

This will install Postfix on your pi.

Now we need to add GPG keys. Run the below command to add them.

curl packages.gitlab.com/gpg.key | sudo apt-key add -

Now, run the below commands, these will both download and install GitLab CE on your PI.

sudo curl -sS https://packages.gitlab.com/install/repositories/gitlab/raspberry-pi2/script.deb.sh | sudo bash

sudo apt-get install gitlab-ce

Configuring your GitLab server

Now it is time to configure our GitLab server (: I will use nano to edit it. Enter the following command to open the configuration file.

sudo nano /etc/gitlab/gitlab.rb

Now, find the line external_url 'gitlab.example.com' and change it with:

external_url 'your_raspberry_pi_address'

change 'your_raspberry_pi_address' with the local IP address of your Raspberry PI ( the same address you used to ssh into the pi )

Now, enter the following command:

sudo gitlab-ctl reconfigure

Done 🎉

yes, that was it, now go to a browser and type your pi's local IP. And here you have your own Gitlab server running on your LAN.

image.png

The default username will be root and the first time opening it will ask you to set up a password. Get done with that and you have your own Git server running on your LAN.

Conclusion

Yes, it is your own git server! Have fun with it, share it with your friends, and keep hacking!

giph

If you need any help in setting it up then you can reach out to me on my Twitter handle. I would love to help you!

Cheers 🎉