How to Create a Local Git Server

A simple method on how to create a git repository on your local server

In this tutorial, I’ll show you how to create a git server in your local network.

You might be thinking why would I? Usually, when we’re working git repository, we go to online services like GitHub. We create a private project for privacy. But that’s not enough for all cases.

You maybe need a git repository to store password. Putting it in a cloud service is not cool.

There is a very simple way to set up your own git server.

I assume you understand how ssh works.

Let’s say you have raspberry pi at home. First, we enter the server remotely via ssh.

$ ssh pi@raspberrypi

Let’s create our project under $HOME/git/myproject.git directory.

$ mkdir -p $HOME/git/myproject.git

Change your working directory there.

$ cd $HOME/git/myproject.git

Create a bare git repository.

$ git init --bare
Initialized empty Git repository in /home/pi/git/myproject.git/

Now get back to your local machine. Open a terminal and clone this newly created git repository.

$ git clone pi@raspberrypi:git/myproject.git
Cloning into 'myproject'...
warning: You appear to have cloned an empty repository.

Then do whatever you do with that git repository. That’s it.

Cover Photo by Pankaj Patel on Unsplash