Skip to content

Simple Git Server for a Home Lab

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://[email protected]/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://[email protected]/home/git/repos/<new-repo>

Created: 2021-06-05 12:24
Last update: 2021-09-01 02:37