Mirroring reposetories

Mirror an exsiting GitHub project to a GitLab project

Within its repository mirroring , GitLab offers a mirroring method called push mirrorring . This method can be used to move the development of an existing GitHub project to GitLab to use GitLab's CI/CD and project features, while the repository still exists on GitHub. After the mirroring is set, the development will take place in GitLab and the GitHub project will passively receive copies of the branches and commits made to GitLab's project.

Import the project as a new GitLab project

In this example, the GitHub project Elephant exists within the GitHub organization ElephantOrg. To import the existing GitHub project at https://github.com/ElephantOrg-org/Elephant to GitLab, first go to GitLab and create a group called ElephantGroup. Then, navigate to https://gitlab.com/ElephantGroup and create a new project. Choose the Run CI/CD for external repository option. Set Git repository URL to https://github.com/ElephantOrg-org/Elephant. and if the GitHub repository is private, set Username to GITHUB_USERNAME and Password to GITHUB_TOKEN . Set project name (Elephant-lab) and visibility level, and click on submit.

Set up a mirroring repository

Once the project is created, navigate to the project page at https://gitlab.com/ElephantGroup/Elephant-lab, go to settings/Repository/Mirroring repositories and add a new mirror repository, set Mirror direction to push and fill the rest of the form like the previous form. Now the mirror downstream is created successfully.

The Mirroring

Create the first GitLab issue with the title: Create CI/CD and mirroring. Set the issue description to:

Create a merge request and branch 1-create-ci-cd-and-mirroring to close this issue. To this new branch, push a .gitlab-ci.yml file containig:
build-job:
    script:
    - echo "Hello, $GITLAB_USER_LOGIN!"
Now the branch https://github.com/ElephantOrg-org/Elephant/tree/1-create-ci-cd-and-mirroring is automatically created! Next blog post will explore the use cases of this workflow by setting up a GitLab CI for a Python project.