I manage my code on a local git repository on my desktop. But I want to access the git repository also from my local laptop or via VPN from remote. This requirement needs to convert the local repository into a remote repository. I'm running a Raspberry as my LAN server which is online all the day and is a perfect git server.

There are a lot of articles in the net how to achieve this. Finally I managed to find my way to get it done. It's not difficult but you have to know what you have to do.

 

Move of a local git repository to a remote git server

First of all the .git directory of the local repository has to be tared.

cd /home/framp/raspiBackup/.git 

tar -pcf ../raspiBackup.tar *

Now create on the git server (raspifix is my server) a directory /home/framp/git/raspiBackup.git and untar the git repository

tar -xf raspiBackup.tar *

Next step is to change the git repository into a bare repository.

git config --bool core.bare true

and now the remote repository is ready to be used.

It may be useful to save the current local repository just in case.

mv /home/framp/raspiBackup /home/framp/raspiBackup_local

Now create a new repository on your local system which connects to the remote repository

cd /home/framp
git clone framp@raspifix:/home/framp/raspiBackup

Now you have to copy your public key ~/.ssh/id_rsa.pubto the server. If ther is no public key already generate its with no passphrase (otherwise you have to configure and use the ssh-agent which is overkill in a local network.

ssh-keygen

and now copy the key

ssh-copy-id framp@raspifix

to the server. Finally adjust your config files in the .git directory.

Now enjoy to share the code between different clients.

 

Define a dedicated user for the remote git repository

sudo adduser git
su git
cd
mkdir .ssh

Now disable remote access to git via ssh.  Edit /etc/passwd and change the line

git:x:1001:1002:,,,:/home/git:/bin/bash

into

git:x:1001:1002:,,,:/home/git:/usr/bin/git-shell

Now every user who should be able to acces the remote git has to pass its ssh key ~./ssh/ir_rsa.pub to the server administrator which appends the key as user git to /home/git/.ssh/authorized_keys.

Now every user can acces the reote repository (Us user git instead of framp now)

cd /home/framp
git clone git@raspifix:/home/framp/raspiBackup

Now enjoy to share the code between different clients.

 

There is another appoache to use Linux groups to grant acces to the git (e.g.. development group). See the following links for details on this.

 

Links

How To Create a Remote Shared Git Repository

Git Website

Git Reference

Add comment

Spam Kommentare sind sinnlos !
Vor der Publizierung wird jeder Beitrag auf Spam geprüft. Leider dauert es deswegen bis ein Kommentar sichtbar wird. Dafür erhält aber kein Subscriber Spam eMails.
Die eMail ist optional und nicht öffentlich sichtbar. Sie ist notwendig um eMail Benachrichtigungen zu Antworten auf Kommentare zu erhalten und wird u.U. genutzt um offline zu kommunizieren.

Spam comments are useless !
Any comment will be reviewed first and checked for spam. Unfortunately this delays the publishing of comments but will protect subscribers from spam.
eMail is optional and hidden and is required get update notifications for any comments and may be used to contact you offline