Imagine that your all repos are hosted on GitHub but you wanna use GitLab's CI/CD for them instead of GitHub actions. So, in today's article, I am going to show you, how we can use GitLab CICD with GitHub Repository.

Create GitHub Access Token

To connect our GitHub Repositories with GitLab, we need to create a GitHub Access Token. You should have GitHub Owner Role to perfome this action

To create a GitHub Access Token, follow the steps below:

  1. Go to your GitHub account and navigate to Settings->token->new
  2. Create a Personal Access Token
  3. Give it a description(optional) and update the scope to allow repo and admin:repo_hook. By allowing above scopes, GitLab can access your project, update commit statuses, and create a web hook to notify GitLab of new commits

Note: You need to store this Access Token in a safe place because we need this Token for our future steps

Create new GitLab project

Now, we need to create a new GitLab project. To create a new project, follow the steps below:
  1. Navigate to Projects-> Create new project

  2. Select Run CI/CD for external repository

  3. Select GitHub as the source

  4. Enter your GitHub Access Token

  5. Search your GitHub Repository name and import it

Configure Pull Mirroring

Now, we need to enable Pull Mirroring for our GitLab project, follow the steps below:
  1. Navigate to your imported project
  2. Then navigate to Settings->Repository->Mirroring repositories
  3. Now expand it and add details related to your project and configure other settings according to your requirements
  4. After all click on Mirror Repository

Add .gitlab-ci.yml to GitHub project

Finally navigate to your GitHub Project and add .gitlab-ci.yml file. This file contains all the CI/CD configuration for your project. In this GitHub repository, I have provided simple CI/CD configuration for testing our pipeline is working. Now, we need to make a little change on our local project and push it to the the GitHub. Now, You can see it will run our pipline in GitLab project's pipeline sction successfully.


In this tutorial, we learned how we can use GitLab CICD with GitHub Repository. If you have any issue regarding this tutorial, mention your issue in comment section or reach me through my E-mail.

Happy Coding