Photo by Sigmund on Unsplash
Photo by Sigmund on Unsplash

First steps with git server; the right way

Yay! What’s up? On this article we will summarize the first steps everyone should follow when it comes to deploying your own Git server. Don’t have any yet? Read this article.

Keep in mind that any host with the Git software installed and Internet connection can be a Git server, you just need to configure a SSH connection to be able to use it.

You can install Git on your Raspberry Pi, a virtual machine on your server, on the cloud… Whatever you want, just install it!

Remote server

Ok, right. Now you have the Git software installed, but you need to create the repository first. How to do it? Very simple, just go to the directory where you want to set up the repository (remember! It needs to be accessible through SSH):

# change directory
cd /home/cooluser/repositories/

# make new directory with .git extension
mkdir coolrepo.git

# come inside
cd coolrepo.git

# run the init command
git init --bare

Local machine

Create the directory where you want to have this repository

mkdir coolrepo
cd coolrepo

Now, you need to prepare this directory for git:

git init
git add .
git commit -m "First commit" -a
git remote add origin ssh://sshuser@server_ip:/home/cooluser/repositories/coolrepo.git
git push origin master

Et voila, you have your own repository with full functionality.

In the future, you can do a git clone like:

git clone sshuser@server_ip:/home/cooluser/repositories/coolrepo.git