[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-11。"],[],[],null,["# Mirroring a GitHub repository\n\nThis topic describes how to mirror a GitHub repository to Cloud Source Repositories.\nWith this configuration, commits that you push to the GitHub repository are\ncopied, or *mirrored*, into a repository hosted in Cloud Source Repositories.\n\nOnly Bitbucket Cloud and GitHub Cloud repositories can be mirrored to\nCloud Source Repositories; self-hosted Bitbucket and GitHub mirroring are not\nsupported.\n\nIf you are mirroring your GitHub repository to Cloud Source Repositories to integrate\nwith Cloud Build and do not need any other Cloud Source Repositories features,\nfollow the Cloud Build instructions on\n[building repositories from GitHub](/build/docs/automating-builds/build-repos-from-github)\ninstead.\n\nBefore you begin\n----------------\n\nWhen you mirror a repository, you must provide GitHub authentication\ncredentials. These credentials let Cloud Source Repositories access the\ncontents of the GitHub repository.\n\nIf you're using\n[GitHub organizations](https://help.github.com/articles/about-organizations/),\nwe recommend that you use a\n[machine user account](https://developer.github.com/v3/guides/managing-deploy-keys/#machine-users)\nspecifically dedicated to automated tasks,\nsuch as mirroring a repository. This account must have administrative access\nto your repository.\n\nMirror a GitHub repository\n--------------------------\n\nThis section shows how to mirror a GitHub repository to\nCloud Source Repositories.\n| **Note:** Make sure you're signed out of GitHub before you mirror a repository. Signing out helps ensure you select the right GitHub account when you connect the GitHub repository to Cloud Source Repositories.\n\n### Create a mirrored repository\n\nIn this process, you need your GitHub machine user credentials to grant\nGoogle Cloud read access to the GitHub repository.\n\n1. In the Google Cloud console, open Cloud Source Repositories.\n\n [Open Cloud Source Repositories](https://source.cloud.google.com/repos)\n2. Click **Add repository**.\n\n The **Add a repository** page opens.\n3. Select **Connect external repository** and click **Continue**.\n\n The **Connect external repository** page opens.\n4. In the **Project** drop-down list, select the Google Cloud\n project to which the mirrored repository belongs.\n\n If you don't have a project, you can click **Create project** to\n [create a project](https://cloud.google.com/source-repositories/docs/creating-an-empty-repository#creating_a_project).\n5. In the **Git provider** drop-down list, select **GitHub**.\n\n6. Select the checkbox to authorize Cloud Source Repositories to store your\n credentials.\n\n7. Click **Connect to GitHub**.\n\n8. Sign in to GitHub with your machine user credentials.\n\n9. Click **Authorize GoogleCloudPlatform**.\n\n This option grants Google Cloud read access to all repositories in the\n GitHub user account.\n\n When authorization finishes, you're returned to the **Connect external\n repository** page. A list of repositories opens.\n10. From the list of repositories, select the repository you want to mirror.\n\n11. Click **Connect Selected Repository**.\n\n The main repository page opens. This page contains a list of the\n repositories for this Google Cloud project, including the new\n repository you just created.\n\n### Identify GitHub repositories\n\nCloud Source Repositories makes it clear which of your repositories are\nmirrors of GitHub repositories:\n\n- Each GitHub repository is represented with the GitHub logo.\n- The name of the repository has `github_` added to the beginning of its name.\n\nForce a repository sync\n-----------------------\n\nAfter you set up mirroring, Cloud Source Repositories automatically syncs\nyour repository with the mirrored repository when a user commits a change.\nCloud Source Repositories lets you view the last time your mirrored\nrepository was synced and manually force a sync if necessary.\n\n1. In the Google Cloud console, browse to the mirrored GitHub repository.\n\n2. Click\n **Settings** *settings*.\n\n The sync status is displayed.\n\n3. To manually force a sync of the repositories, click **Sync from GitHub**.\n\n| **Note:** Repositories connected using an older version of the connected repository service may not have these options."]]