Blog

Mirroring Github to Gitlab…Without Premium

By Jay

Apr 18, 2024 | 3 minutes read

Series: HomeLab

Tags: blog, tech

In the world of software development, synchronization and backup of code repositories across different platforms are vital for robust development practices. Many organizations use GitHub for source control while leveraging GitLab for CI/CD and project management. However, GitLab’s premium feature—repository mirroring—comes with a significant cost: $348 per year. This cost can be prohibitive for smaller teams, startups, or individual developers who require mirroring functionality for one-off tests or limited-time projects. This blog post outlines a practical solution that allows effective repository mirroring from GitHub to GitLab without the need for a premium subscription.

Repository mirroring is not just about redundancy; it’s an essential strategy that enhances workflow efficiency, reduces risks associated with single points of failure, and facilitates smoother integration and testing processes. For instance, having a mirror of your production repository on GitLab can allow you to leverage GitLab’s powerful CI/CD pipelines and advanced issue tracking, all while continuing to manage 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.

Our solution involves using open-source tools and scripts to set up your own mirroring mechanism. This DIY approach is not only cost-effective but also provides flexibility to customize the mirroring process according to specific needs without being tied to vendor-specific limitations.

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.

Mirroring your GitHub repositories to a locally hosted GitLab instance without paying for GitLab Premium is not only feasible but also a smart choice for budget-conscious teams. By following the steps outlined in this blog, teams can enjoy the best of both platforms without incurring high costs. This solution empowers developers to maintain operational efficiency and leverage advanced tools irrespective of budget constraints.

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.