How to mirror your GitLab repository

If you're a GitLab user, you should consider mirroring your repositories to a remote location.

How to mirror your GitLab repository

You never know what might happen. You've spent months on your code, housing it in GitLab. And then, out of nowhere, everything is gone. Chances are you have a clone of that code somewhere, but why leave it to chance, when you could use the GitLab built-in repository mirroring tool?

That's right. GitLab includes the ability to create remote mirrors for your repositories. With this tool, you can mirror your work to any remote repository that is accessible to the outside world.

I'm going to show you how to mirror a GitLab repository to a GitHub repository. You'll be surprised at how easy this is.

SEE: The top 10 languages for machine learning hosted on GitHub (free PDF) (TechRepublic)

What you'll need

The only things you'll need are:

  • A GitLab account with a repository to clone

  • A GitHub account with a repository that can be used to house the clone

How to create the mirror

Log into your GitLab account and click Projects in the upper left corner. From the drop-down, select Your Projects. In the resulting window, click the project you want to mirror. In the project's left sidebar, click the Settings and then select Repository (Figure A).

Figure A


Accessing the repository settings window.

In the resulting window, click the Expand button associated with Mirroring repositories. In this new window (Figure B), you must enter the URL for the remote GitHub repository in the form of:​

Where USERNAME is the name of your GitHub user and REPOSITORY is the name of the remote repository to house the mirror.

Figure B


Configuring the mirror.

In the Mirror direction, select Push, and in the password section, select Password. Type the password for your GitHub user and then click Mirror Repository. Your mirror configuration is now saved and will appear below the configuration section (Figure C).

Figure C


Our newly created mirror is ready to go.

If you click the Sync button (the button directly to the left of the trashcan), the mirror will sync. Depending on how much code you have in the repository, this can take some time. If all has been set up correctly, you should see no errors and your GitLab repository has been successfully mirrored to GitHub.

And that's all there is to setting up a repository mirror from GitLab to GitHub. If you house your code on this service, you owe it to yourself (and all the hard work you've put in) to have numerous copies of that code. Gitlab makes this both possible and easy.

Also see


Image: Jack Wallen