Simple Git Server for a Home Lab

radar23131st August 2021 at 10:37pm

References

Introduction

There are a number of different git servers available, including a built in daemon (git-daemon). While implementations like gitea or gogs are quite suitable for a home lab environment, sometimes even those are more complex that what is really required. The simplest git server is nothing more than an account on an ssh reachable server hosting the git repos.

Server Account Setup

  • Create an account named 'git' on a suitable server
  • Set up SSH for the 'git' account, and add the SSH public keys of all users that will be accessing the hosted repos to the "~/.ssh/authorized_keys" file of the 'git' account
  • Create a directory (ie, named 'repos') in the 'git' user home directory to hold the hosted git repos

Initial Git Repo Setup

  • As the 'git' user, create a directory named for the new repo in the 'repos' directory, and initialize it as an empty git repo
$ mkdir repos/<new-repo>
$ cd repos/<new-repo>
$ git init --bare
  • On the dev workstation, initialize the code directory as a git repo. Add the existing files and do the initial checkin
$ git init
$ git add .
$ git commit -m "initial checkin"
  • Add the location on the git server as the remote repo for the new git repo. Perform the initial push of the files to the git server
$ git remote add origin ssh://git@git.lan/home/git/repos/<new-repo>
$ git push --set-upstream origin master

Using the new Git Repo

  • Further usage of the git repo will only require a 'git push'
(make edits, add files, etc)
$ git add .
$ git commit -m "<commit message>"
$ git push
  • To perform a checkout of the repo to a new server/location
$ git clone ssh://git@git.lan/home/git/repos/<new-repo>

....................
(created: 2021-06-05, last modified: 2021-08-31 at 22:37:07)