This is a naïve implementation. Probably will be improved in the future. I really don't know how it is implemented GitHub backend and I don't pretend to achieve such a level of complexity. I only need a simple structure for a server where I host some git repos.
This article does not contain web interface setup instructions.

Structure

I really like GitHub structure! It is a three level hierarchy:

  1. A server, ehm github.com.
  2. Server’s users, for example fibo.
  3. User’s git repos, like this.

It keeps everything clean specially when collaborative coding lead to fork repos: basically, it let coexist cnorris/repofoo fork of jsmith/repofoo.

How to

In your Unix server gitbox.example.org, create user jsmith. Keep in mind that a user is just the second level of the tree. It can be a real person, an organization, or whatever groups a set of repos. For example I use to create a user for everyone of my customers, but, it could make sense also to create a user for every project.

In Unix context, a user will own a home folder: usually /home/jsmith. This folder will contain user’s git repos.

Create master git repo

On gitbox.example.org, as jsmith user, create a repofoo git repo.

Create repo folder under the home and cd into it.

mkdir ~/repofoo.git && cd $_

The trick is to create a bare git repo, in order to be able to push to it.

$ git init --bare
Initialized empty Git repository in /home/jsmith/repofoo.git/

Clone repo locally

Now on your laptop, or any other host you will use for development, you can clone repo via ssh. I like to reflect the same tree structure also on folders, so in my laptop I do

mkdir -p ~/gitbox.example.org/jsmith && cd $_

then I clone repofoo with

git clone [email protected]:~/repofoo.git

Port local repo on server

A common scenario is init a repo locally, and then put it on git server lately. First create master git repo, repobar for instance. I assume you already created repobar locally with git init. Then go into your local repobar folder and add the remote origin and set upstream master.

cd ~/gitbox.example.org/jsmith/repobar
git remote add origin [email protected]:~/repofoo.git
git push --set-upstream origin master

Now you can push repobar commits from your laptop to gitbox.example.org

References

Git on the Server