Self-host a minimal git repo over SSH

Did you know it's super easy to self-host a git repo over SSH? If you're not looking for a full web based git interface (like GitHub, Gitea etc.) you can use the steps below to set up a simple repo over SSH. All you need is SSH access to a server that you own. You can set up as many self-hosted repos as you like. It can even be as simple as a raspberry Pi on your local network.

There are two simple parts to this. First you set up the remote server one time only. Next you add the remote server as a remote for your local repo. After that you can just git push as normal.

Remote setup

To get started SSH into the box where you want the repo to be hosted:

ssh user@example.com

Next you're going to create a folder for the repo, cd into it, and create a bare git repo:

mkdir my_repo_name.git
cd my_repo_name.git
git init --bare

If you want to also serve a read-only copy of this repo over HTTP, then make sure the folder is in a public web root, and run this:

git update-server-info

Local setup

Now you can add this git remote to your existing git repo just like normal:

git remote add origin user@example.com:my_repo_name.git
git push -u origin master

There you go, you now have a self-hosted remote you can push to over SSH. If you want this to be a backup repo you can add it with a name other than origin like this:

git remote add backup user@example.com:my_repo_name.git
git push backup master

After this any time you want to push to backup instead of origin you just do: git push backup.

Hosted Gitea is a fully managed Gitea hosting service. If you're looking for a private alternative to GitHub or Gitlab check out our service.

Get your Gitea server