2019-09-04 21:01:54 +05:30
---
2020-06-23 00:09:42 +05:30
stage: Verify
group: Continuous Integration
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#designated-technical-writers
2019-09-04 21:01:54 +05:30
type: howto
---
2019-09-30 21:07:59 +05:30
# Using GitLab CI/CD with a GitHub repository **(PREMIUM)**
2019-07-31 22:56:46 +05:30
GitLab CI/CD can be used with **GitHub.com** and **GitHub Enterprise** by
2019-09-04 21:01:54 +05:30
creating a [CI/CD project ](index.md ) to connect your GitHub repository to
2019-07-31 22:56:46 +05:30
GitLab.
2019-09-04 21:01:54 +05:30
< i class = "fa fa-youtube-play youtube" aria-hidden = "true" > < / i >
Watch a video on [Using GitLab CI/CD pipelines with GitHub repositories ](https://www.youtube.com/watch?v=qgl3F2j-1cI ).
2019-07-31 22:56:46 +05:30
2019-12-04 20:38:33 +05:30
NOTE: **Note:**
2020-06-23 00:09:42 +05:30
Because of [GitHub limitations ](https://gitlab.com/gitlab-org/gitlab/-/issues/9147 ),
2020-03-13 15:44:24 +05:30
[GitHub OAuth ](../../integration/github.md#enabling-github-oauth )
2019-12-04 20:38:33 +05:30
cannot be used to authenticate with GitHub as an external CI/CD repository.
2019-07-31 22:56:46 +05:30
## Connect with Personal Access Token
2019-09-04 21:01:54 +05:30
NOTE: **Note:**
Personal access tokens can only be used to connect GitHub.com
2020-06-23 00:09:42 +05:30
repositories to GitLab, and the GitHub user must have the [owner role ](https://help.github.com/en/github/getting-started-with-github/access-permissions-on-github ).
2019-07-31 22:56:46 +05:30
2019-12-04 20:38:33 +05:30
To perform a one-off authorization with GitHub to grant GitLab access your
2019-07-31 22:56:46 +05:30
repositories:
2019-09-04 21:01:54 +05:30
1. Open < https: // github . com / settings / tokens / new > to create a **Personal Access
2019-12-26 22:10:19 +05:30
Token**. This token will be used to access your repository and push commit
2019-07-31 22:56:46 +05:30
statuses to GitHub.
2019-09-04 21:01:54 +05:30
2019-10-12 21:52:04 +05:30
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.
2019-07-31 22:56:46 +05:30
2020-06-23 00:09:42 +05:30
1. In GitLab, go to the [new project page ](../../gitlab-basics/create-project.md#create-a-project-in-gitlab ), select the **CI/CD for external repo** tab, and then click
2019-07-31 22:56:46 +05:30
**GitHub** .
1. Paste the token into the **Personal access token** field and click **List
Repositories**. Click **Connect** to select the repository.
1. In GitHub, add a `.gitlab-ci.yml` to [configure GitLab CI/CD ](../quick_start/README.md ).
2019-12-04 20:38:33 +05:30
GitLab will:
1. Import the project.
2019-12-26 22:10:19 +05:30
1. Enable [Pull Mirroring ](../../user/project/repository/repository_mirroring.md#pulling-from-a-remote-repository-starter )
2019-12-04 20:38:33 +05:30
1. Enable [GitHub project integration ](../../user/project/integrations/github.md )
1. Create a web hook on GitHub to notify GitLab of new commits.
2019-07-31 22:56:46 +05:30
## Connect manually
2019-09-04 21:01:54 +05:30
NOTE: **Note:**
2019-12-04 20:38:33 +05:30
To use **GitHub Enterprise** with **GitLab.com** , use this method.
2019-09-04 21:01:54 +05:30
2019-12-04 20:38:33 +05:30
To manually enable GitLab CI/CD for your repository:
2019-07-31 22:56:46 +05:30
2019-09-04 21:01:54 +05:30
1. In GitHub open < https: // github . com / settings / tokens / new > create a **Personal
2019-07-31 22:56:46 +05:30
Access Token.** GitLab will use this token to access your repository and
push commit statuses.
2019-09-04 21:01:54 +05:30
2019-10-12 21:52:04 +05:30
Enter a **Token description** and update the scope to allow:
2019-07-31 22:56:46 +05:30
2019-10-12 21:52:04 +05:30
`repo` so that GitLab can access your project and update commit statuses
2019-07-31 22:56:46 +05:30
1. 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.
2019-10-12 21:52:04 +05:30
GitLab will automatically configure polling-based pull mirroring.
2019-07-31 22:56:46 +05:30
2019-09-04 21:01:54 +05:30
1. Still in GitLab, enable the [GitHub project integration ](../../user/project/integrations/github.md )
2019-07-31 22:56:46 +05:30
from **Settings > Integrations.**
2019-10-12 21:52:04 +05:30
Check the **Active** checkbox to enable the integration, paste your
personal access token and HTTPS repository URL into the form, and **Save.**
2019-07-31 22:56:46 +05:30
1. Still in GitLab create a **Personal Access Token** with `API` scope to
authenticate the GitHub web hook notifying GitLab of new commits.
1. In GitHub from **Settings > Webhooks** create a web hook to notify GitLab of
new commits.
2019-10-12 21:52:04 +05:30
The web hook URL should be set to the GitLab API to
[trigger pull mirroring ](../../api/projects.md#start-the-pull-mirroring-process-for-a-project-starter ),
2020-03-13 15:44:24 +05:30
using the GitLab personal access token we just created:
2019-07-31 22:56:46 +05:30
2020-03-13 15:44:24 +05:30
```plaintext
2019-10-12 21:52:04 +05:30
https://gitlab.com/api/v4/projects/< NAMESPACE > %2F< PROJECT > /mirror/pull?private_token=< PERSONAL_ACCESS_TOKEN >
```
2019-07-31 22:56:46 +05:30
2020-06-23 00:09:42 +05:30
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 ](index.md#pipelines-for-external-pull-requests ).
2019-07-31 22:56:46 +05:30
1. In GitHub add a `.gitlab-ci.yml` to configure GitLab CI/CD.
2019-09-04 21:01:54 +05:30
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
one might have when setting this up, or when something is changed, or on upgrading, it's
important to describe those, too. Think of things that may go wrong and include them here.
This is important to minimize requests for support, and to avoid doc comments with
questions that you know someone might ask.
Each scenario can be a third-level heading, e.g. `### Getting error message X` .
If you have none to add when creating a doc, leave this section in place
but commented out to help encourage others to add to it in the future. -->