Mirror a GitHub repository to GitLab with a simple cronjob

#linux

In the free version of GitLab, you can do development on GitLab and make a mirror of that repository to GItHub. However, if you try doing the opposite, you're gonna hit a paywall, as pulling from a remote repository is a premium feature.

To replicate this issue without paying, assuming you have access to a constantly-running Linux box (even a Raspberry Pi would do):

How to

Create a blank repository on GitLab. Be sure adding a README file is disabled.

# Clone a GitHub repository
git clone https://github.com/username/project

# Add a GitLab repository as a repote
git remote add gitlab git@gitlab.com:username/project

Finally, add a cronjob (crontab -e, at the bottom):

*/2  * * * * cd /path/to/repository && git pull origin && git push gitlab

Voila!


Unless specified otherwise, this work is licensed under a Creative Commons BY-NC-SA 4.0.