Index ¦ Archives ¦ Atom

Host your own git repository

Say you want a git repository that is accessible by one or more remote systems. This may be to privately share code within a team of developers, or just to easily remotely backup your own code.

You'll need a 'server'. I'm partial to FreeBSD VPS offerings from ARP Networks, but this should work with anything Linux-ish (Linode, AWS EC2, and so on.

On the server, create a bare git repository (assuming you may have more than one, we'll put them in ~/git):

$ mkdir -p ~/git/testrepo
$ cd ~/git/testrepo
$ git init --bare

You will never actually work directly inside this repo.

On your client/working systems, clone the repo from the server:

$ git clone ssh://user@server:/home/user/git/testrepo
$ cd testrepo
[make changes/commits]
$ git push

That's it .. clone it via SSH to as many systems as you like. Setting up SSH keys is a nice way to avoid having to type in passwords every time you push to your remote repository. If you have multiple individuals needing access, then you may want to setup multiple user accounts / keys, use a shared location on the filesystem, and set server-side permissions appropriately.

If you want to work directly on the server, then you'll need to clone the bare repo locally:

$ cd ~/working
$ git clone /home/user/git/testrepo
[...]

This is about as simple as it gets, but may be all you need. If it's a bit bare-bones for your liking, Gitea is a nice self-hosted web UI option, or on the hosted-service front there's GitHub, GitLab, AWS CodeCommit, and many other options.

© Jamie Finnigan. Built using Pelican. Modified from theme by Giulio Fidente on github.