Daniel's blog

A Simple Git Server

Have you ever wondered (probably not) what happens if you try to use the user and the remote destination from the git clone SSH command from any GitHub-hosted workspace?

It will show you the following:

1ssh git@github.com
2
3PTY allocation request failed
4Hi xFuture603! You've successfully authenticated, but GitHub does not provide shell access.
5Shared connection to github.com closed.

This probably isn’t new, but I came across it while searching for the simplest way to self-host a remote Git repo without installing something like GitLab or Forgejo.

I remembered that you can simply install git on the server , and while researching I stumbled across the --bare parameter, which lets you git clone or git init just the repository itself without the workspace.

As a prerequisite, we need a remote server that we can access via SSH. This is both an advantage and a limitation, because every collaborator needs SSH access to this server.

So let’s get started and create the repository. Connect to your remote client and initialize a bare git repository:

1git init --bare code_repo

The content of a bare git repository is currently just the content of your normal .git folder that you find in your local workspaces.

1ls -1
2
3config
4description
5HEAD
6hooks
7info
8objects
9refs

Now, if you are a user with SSH access, you can use SSH URLs to perform various Git commands. For example, on your local machine you can run:

1git clone $user@$remote_client:code_repo

This will clone your code_repo repository to your local machine.

Once cloned, you can edit or add files and work as usual. To push your changes back to the remote origin, you follow the normal workflow:

1git add $file
2
3git commit -m 'My commit message'
4
5git push origin main

If you have multiple persons that want to collaborate from their local machines, you now can use git clone and start working with the repository, as long as you have SSH access to the remote host.

Sometimes things are simple and you don’t need a self-hosted solution for a small task (note to myself).

Sources

Git on the Server - https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols.html

← Previous Post

|

Next Post →