GitLab the Git Distributor

Published:
Talks about: , , , , , and

Git at its core is a decentralized version control system. Yet a lot of people are relying on a single central server (github.com at the time of this writing) to share their work with others. Pro Git rightfully mentions it at first position in its chapter about distributed workflows because using a central server is usually the simplest approach to sharing code.

While the central server approach is easy to use, it might not work in all scenarios:

  1. An enterprise wants to share internal code as part of an open source project. All development is happening internally, and the public mirror gets an occasional update once in a while.
  2. In order to protect against outages of the central server, mirrors should be created and be kept up-to-date.

In case of the first scenario, tools like copybara, repoSpanner, or distributed-git-forks offer a wide range of features to cover most details.

The second scenario can be solved manually with tools like gitomatic or automatically with GitLab’s mirror feature quite easy. GitLab allows to create a single pull-mirror and multiple push-mirrors. Thus, it can be used to pull from your central server and push into all mirrors.

               +----------------+               
               |     GitHub     |               
               +----------------+               
                        ^                       
                        |                       
                        |                       
               +----------------+               
         +-----|     GitLab     |------+        
         |     +----------------+      |        
         |                             |        
         |                             |        
         v                             v        
+----------------+            +----------------+
|    Codeberg    |            |    BitBucket   |
+----------------+            +----------------+

In order to create such a setup, follow these steps:

  1. Go to Settings > Repository and expand Mirroring repositories Code Flow
  2. Enter the URL of your central Git repository as the pull source, e.g. https://github.com/metio/krei.git Code Flow
  3. Enter one push target for each mirror. Since pushing usually requires authentication, make sure the URL of the mirror contains a username, e.g. https://YOUR_USER@codeberg.org/metio.wtf/krei.git. Add an access token for each mirror and select password as authentication method. Code Flow

In case you prefer SSH keys over HTTP access tokens, just select SSH public key as authentication method and make sure your key is both saved in GitLab and all mirrors.

Examples Projects

The following projects are using the above approach to synchronize multiple git repositories: