Using GitLab CI/CD with a GitHub repository

GitLab CI/CD can be used with and GitHub Enterprise by creating a CI/CD project to connect your GitHub repository to GitLab.

Watch a video on Using GitLab CI/CD pipelines with GitHub repositories.

Note: Because of GitHub limitations, GitHub OAuth cannot be used to authenticate with GitHub as an external CI/CD repository.

Connect with Personal Access Token

Note: Personal access tokens can only be used to connect repositories to GitLab, and the GitHub user must have the owner role.

To perform a one-off authorization with GitHub to grant GitLab access your repositories:

  1. Open to create a Personal Access Token. This token will be used to access your repository and push commit statuses to GitHub.

    The repo and admin:repo_hook should be enable to allow GitLab access to your project, update commit statuses, and create a web hook to notify GitLab of new commits.

  2. In GitLab, go to the new project page, select the CI/CD for external repo tab, and then click GitHub.

  3. Paste the token into the Personal access token field and click List Repositories. Click Connect to select the repository.

  4. In GitHub, add a .gitlab-ci.yml to configure GitLab CI/CD.

GitLab will:

  1. Import the project.
  2. Enable Pull Mirroring
  3. Enable GitHub project integration
  4. Create a web hook on GitHub to notify GitLab of new commits.

Connect manually

Note: To use GitHub Enterprise with, use this method.

To manually enable GitLab CI/CD for your repository:

  1. In GitHub open create a Personal Access Token. GitLab will use this token to access your repository and push commit statuses.

    Enter a Token description and update the scope to allow:

    repo so that GitLab can access your project and update commit statuses

  2. In GitLab create a CI/CD project using the Git URL option and the HTTPS URL for your GitHub repository. If your project is private, use the personal access token you just created for authentication.

    GitLab will automatically configure polling-based pull mirroring.

  3. Still in GitLab, enable the GitHub project integration from Settings > Integrations.

    Check the Active checkbox to enable the integration, paste your personal access token and HTTPS repository URL into the form, and Save.

  4. Still in GitLab create a Personal Access Token with API scope to authenticate the GitHub web hook notifying GitLab of new commits.

  5. In GitHub from Settings > Webhooks create a web hook to notify GitLab of new commits.

    The web hook URL should be set to the GitLab API to trigger pull mirroring, using the GitLab personal access token we just created:<NAMESPACE>%2F<PROJECT>/mirror/pull?private_token=<PERSONAL_ACCESS_TOKEN>

    Select the Let me select individual events option, then check the Pull requests and Pushes checkboxes. These settings are needed for pipelines for external pull requests.

  6. In GitHub add a .gitlab-ci.yml to configure GitLab CI/CD.