This topic describes how to mirror a GitHub repository to Cloud Source Repositories. With this configuration, commits that you push to the GitHub repository are copied, or mirrored, into a repository hosted in Cloud Source Repositories.
Only Bitbucket Cloud and GitHub Cloud repositories can be mirrorred to Cloud Source Repositories; self-hosted Bitbucket and GitHub mirroring are not supported.
If you are mirroring your GitHub repository to Cloud Source Repositories to integrate with Cloud Build and do not need any other Cloud Source Repositories features, follow the Cloud Build instructions on building repositories from GitHub instead.
Before you begin
When you mirror a repository, you must provide GitHub authentication credentials. These credentials let Cloud Source Repositories access the contents of the GitHub repository.
If you're using GitHub organizations, we recommend that you use a machine user account specifically dedicated to automated tasks, such as mirroring a repository. This account must have administrative access to your repository.
Mirror a GitHub repository
This section shows how to mirror a GitHub repository to Cloud Source Repositories.
Create a mirrored repository
In this process, you need your GitHub machine user credentials to grant Google Cloud read access to the GitHub repository.
In the Google Cloud console, open Cloud Source Repositories.
Click Add repository.
The Add a repository page opens.
Select Connect external repository and click Continue.
The Connect external repository page opens.
In the Project drop-down list, select the Google Cloud project to which the mirrored repository belongs.
If you don't have a project, you can click Create project to create a project.
In the Git provider drop-down list, select GitHub.
Select the checkbox to authorize Cloud Source Repositories to store your credentials.
Click Connect to GitHub.
Sign in to GitHub with your machine user credentials.
Click Authorize GoogleCloudPlatform.
This option grants Google Cloud read access to all repositories in the GitHub user account.
When authorization finishes, you're returned to the Connect external repository page. A list of repositories opens.
From the list of repositories, select the repository you want to mirror.
Click Connect Selected Repository.
The main repository page opens. This page contains a list of the repositories for this Google Cloud project, including the new repository you just created.
Identify GitHub repositories
Cloud Source Repositories makes it clear which of your repositories are mirrors of GitHub repositories:
- Each GitHub repository is represented with the GitHub logo.
- The name of the repository has
github_added to the beginning of its name.
Force a repository sync
After you set up mirroring, Cloud Source Repositories automatically syncs your repository with the mirrored repository when a user commits a change. Cloud Source Repositories lets you view the last time your mirrored repository was synced and manually force a sync if necessary.
In the GCP Console, browse to the mirrored GitHub repository.
Click Settings settings.
The sync status is displayed.
To manually force a sync of the repositories, click Sync from GitHub.