DEV Community

Dmitry Kabanov
Dmitry Kabanov

Posted on

How to mirror GitLab repo to GitHub

If you have a GitLab repo and would like to mirror it in your GitHub account, it can be set up directly in the GitLab repo settings. Note that here we use new fine-grained tokens functionality of GitHub (which is currently in beta, as of May 2023).

Go to the project's settings (Settings -> Repository) and expand "Mirror repository". You will see the following form:
Mirror repository form on GitLab

In the "Git repository URL", you need to specify the HTTPS URL for the repo on GitHub in the following format:
https://github-username@github.com/github-username/repo.git
Note the added username part between // and @ in the above URL --- when you create a repository on GitHub, the generated URLs do not have this, so you need to add it manually!

Now, for a password, we use fine-grained tokens. Press "Generate new token" button and choose read and write permissions for "Contents".

Copy the generated token and paste it into the "Password" field in GitLab. Finally press "Mirror repository" button. Once you see a table with mirrors appeared, you can press "Update now" (two arrows) button to check if everything works correctly.

Right now, usability is a bit off, as if something is not working, you have to delete the mirror and start over again. It would be a better user experience, if GitLab allowed to edit the mirror settings.

Hopefully, these instructions work good for you. Enjoy!

P.S. This two StackOverflow posts were really helpful to write the above instructions:

Top comments (0)