Blog

Lots of shops run GitHub for source control and GitLab for CI/CD and project management. The problem is that GitLab’s repository mirroring is a premium feature at $348 a year, which is hard to justify for small teams or one-off projects. Here’s how to mirror GitHub repositories to GitLab without paying for it.

Beyond redundancy, a mirror on GitLab means you can use its CI/CD pipelines and issue tracking while still managing your code on GitHub.

GitLab’s repository mirroring is an excellent feature but is gated behind their premium tier, costing $29/month when billed annually. For large corporations, this fee is a drop in the bucket. However, for smaller teams or projects with tight budgets, saving on these costs while maintaining a high level of operational efficiency can be crucial.

The solution uses open-source tools and scripts to set up your own mirroring. It costs nothing and you can customize it however you like.

Before you begin, you’ll need:

  • Administrative access to both GitHub and GitLab.
  • Personal Access Tokens from GitHub with repo scope and from GitLab with api scope.
  • Python3 and Bash environment to execute the provided scripts.

The process involves several steps:

  1. Clone the Repository: Start by cloning this repository which contains all necessary scripts.
  2. Configure Environment Variables: Set up your environment variables using the provided .env example file.
  3. Install Dependencies: Use Python to install required libraries.
  4. Creating and Syncing Projects: Use the scripts to create new projects in GitLab and sync them with your GitHub repositories.
  1. Use the gl_repo_create.py script to create new GitLab projects.
  2. Execute the setup_mirror.sh for each repository you want to mirror.
  3. Regularly synchronize your repositories by running update_mirror.sh.

To ensure your repositories are always synchronized, you can set up a cron job that runs at intervals you define.

This method is particularly advantageous for:

  • Testing and One-off Projects: Ideal for temporary or experimental projects where permanent mirroring is not required.
  • Cost Reduction: Avoids the need for an expensive premium subscription.
  • Customization: Offers flexibility to tweak the mirroring process to better fit your workflow.

That’s it. A cron job and two scripts get you GitHub-to-GitLab mirroring for free, which leaves the $348 in your budget for something that actually needs paying for.

Special thanks to “The Queen of RBAC” for insights that significantly contributed to the development of these scripts.

Remember, while this approach saves costs, supporting platforms like GitLab through subscriptions can also be beneficial if their features add value to your projects and you have the budget for it. This balance between cost-saving and support for development platforms is crucial for sustaining a healthy ecosystem in software development.