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.
Before you begin
When you mirror a repository, you must provide GitHub authentication credentials. These credentials allow Cloud Source Repositories to access the contents of the GitHub repository.
If you are using GitHub organizations, it is recommended that you use a machine user account that is specifically dedicated to automated tasks, such as mirroring a repository. This account must have administrative access to your repository.
Mirroring a GitHub repository
The following sections describe how to mirror a GitHub repository to Cloud Source Repositories.
Add a new repository
Open Cloud Source Repositories in the console:
Click Add Repository, located in the top right corner.
The New Repository screen opens.
Select Connect external repository.
The Connect External Repository screen opens.
From the Project list, select the project for the repository.
To create a new project, click Create Project.
From the Git Provider list, select GitHub.
Check the box to authorize Cloud Source Repositories to store your credentials.
Connect to GitHub
In this step, you sign into GitHub and authorize Google Cloud Platform to have read access to the repository.
Click Connect to GitHub.
Sign in to GitHub using your machine user credentials.
Click Authorize GoogleCloudPlatform.
This option allows Google Cloud Platform read access to your repository.
After the authorization concludes, you are returned to the Connect External Repository screen. A list of repositories opens.
Select the repository you want to mirror.
Click Connect Selected Repository.
The main repository screen opens. This screen contains a list of the repositories for this project, including the new repository you just created.
Identifying GitHub repositories
Cloud Source Repositories makes it easy to identify 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.
Forcing repository sync
Once you have set up mirroring, Cloud Source Repositories automatically syncs your repository with the mirrored repository when a user commits a change. Cloud Source Repositories allows you to view the last time your mirrored repository was synced and manually force a sync if necessary.
Browse to the repository in the source console.
Click the Settings icon in the upper right-hand corner of the display.
The sync status is displayed on the page.
Click Sync from GitHub to manually force a sync of the repositories.