Setting up a github locally
I've wanted to allow all the machines locally (on my intranet) to access a single github repository without needing direct write access to the files that actually host the repo. Fortunately, I found this how-to that I adapted to ensure all my machines could do this. It starts out by using the git
protocol to serve the files. This is insecure if exposed on an external network, but should be fine on my internal network. Here is what I did.
-
I created a local
CNAME
record on my DNS togit.bedewell.com
so that I could serve the set of repo's from any host.cname=git.bedewell.com,rasp-pi
-
On the particular machine that I want to use (one of my Raspberry Pi's) I created a
git
user that would actually be serving the repo's.adduser git --disabled-login
-
On the
rasp-pi
I've mounted a location on my NAS where all the git repositories will be located (/home/git/repos
). -
In
/home/git/.gitconfig
I added the following lines that allow a short cut for serving (as a hub)[alias] hub = !git daemon --base-path=. --export-all --enable=receive-pack --reuseaddr --informative-errors --verbose
-
Using
supervisord
I configured the machine to always rungit hub
on startup - which will allow the machine to serve the appropriate locations under/home/git/repos
(the only important aspect is thatgit hub
must be launched in that directory.
Now - to create a new repository all I need do is become git
on the rasp-pi
, create a new folder (newrepo
) in the repository and do the following in that new folder
git init --shared=all
We will also need to ensure that rasp-pi
is using the master
branch whilst all the remote versions are running another (I use working
)
git checkout -b working
touch README
git add README
git commit -m "init working"
git checkout -b master
Obviously it is easier to put all this in a script to automate the process of making a new repository.
The repo is now ready for use on a remote machine. On the remote machine you simply clone the repository and use the working branch.
git clone git://git.bedewell.com/newrepo
git checkout working
To aid my memory I actually create a README
file on both the master and working branch - in the master version I indicate the user should be using the working branch.