Skip to content

Instantly share code, notes, and snippets.

@AndreaGhizzoni
Last active April 24, 2018 20:10
Show Gist options
  • Save AndreaGhizzoni/ab93631edc58ef4bde9fbf5a6790c3a5 to your computer and use it in GitHub Desktop.
Save AndreaGhizzoni/ab93631edc58ef4bde9fbf5a6790c3a5 to your computer and use it in GitHub Desktop.
gitserver.md

Installing private Git Server

Note while learning how to install a bare private git server.

Sources

dev.to and linux.com

Setting up server

Let's assume we have a server called gitserver.local, with a normal user bob and a working SSH service. Log in with SSH via:

$ ssh bob@gitserver.local

Now install git-core

$ sudo apt-get install git-core -y

Now let's create a dedicate user called git that will handle all the repositories, change his password and log in as git user:

$ useradd -m -d /home/git -s /bin/bash git
$ sudo passwd git
$ su - git
$ whoami
git
$ pwd
/home/git

Now let's assume that Alice want to save his git repository on our gitserver. So create a new folder for Alice and then a folder for her project:

$ mkdir -p alice/prj.git
$ cd alice/prj.git

Now initialize that folder with a bare git repo:

$ git init --bare

Now Alice is free to use his repository.

Setting up a client

Installing and configuring git on Alice machine:

$ sudo apt-get install git -y
$ git config --global user.name "Firstname Lastname" 
$ git config --global user.email "your_email@example.com"

Alice want to push her project on our gitserver. The first thing to do is setting up her RSA keys and copy her public key to the server (that is explained here).

Now Alice can: (1) create a new git working directory and push the changes or (2) clone the repository from gitserver.

1

$ mkdir -p prj && cd prj
$ git init
$ git remote add git@gitserver.local:alice/prj.git

2

$ git clone git@gitserver.local:alice/prj.git prj && cd prj

Then she can work with her repository as usual:

$ echo "HELLO" >> README.md
$ git add . && git commit -m "added readme"
$ git push origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment