Cloning a repository

This topic describes how to clone the contents of a repository from Cloud Source Repositories to your local machine.

Before you can clone the contents of the repository, you must set up authentication on your local system. The steps you perform vary depending on the authentication type.

Cloud Source Repositories supports the following types of authentication:

  • Cloud SDK
  • Manually generated credentials
  • SSH

For more information on authentication types, see Authentication.

Before you begin

You must have a repository in Cloud Source Repositories. To create a new repository, see Creating an Empty Repository.

Using Cloud SDK

Console

  1. Open Cloud Source Repositories in the console:

    Open Cloud Source Repositories

  2. Hover over the repository you want to clone.

  3. Click the Plus (+) icon.

    The Cloning Your Repository screen opens.

  4. Select the Google Cloud SDK option.

  5. Follow the on-screen instructions to clone your repository.

Command line

  1. Open a terminal window.

  2. Install the Google Cloud SDK.

  3. Type the following command to provide your authentication credentials.

    gcloud init
    
  4. Type the following command to clone your repository.

    gcloud source repos clone [REPOSITORY_NAME] --project=[PROJECT_NAME]
    

    Where:

    • [REPOSITORY_NAME] is the name of your repository
    • [PROJECT_NAME] is the name of your project

Using manually generated credentials

If you are not using the Google Cloud SDK, you can clone a repository using manually generated credentials.

Console

  1. Open Cloud Source Repositories in the console:

    Open Cloud Source Repositories

  2. Hover over the repository you want to clone.

  3. Click the Plus (+) icon.

    The Cloning Your Repository screen opens.

  4. Select the Manually generated credentials option.

  5. Follow the on-screen instructions to clone your repository.

Command line

  1. Generate and store your Git credentials.

  2. Open a terminal window.

  3. Type the following command:

    git clone https://source.developers.google.com/p/[PROJECT_NAME]/r/[REPOSITORY_NAME]
    

    Where:

    • [PROJECT_NAME] is the name of your project
    • [REPOSITORY_NAME] is the name of your repository

Using SSH

  1. Set up local authentication with SSH.

  2. On your local system, clone the repository using your Google Cloud Platform username and the fully-qualified SSH path to your repository:

    git clone ssh://EMAIL@source.developers.google.com:2022/p/PROJECT_ID/r/REPO_NAME
    

    where EMAIL is your GCP username, PROJECT_ID is the ID of the project where the repository is located, and REPO_NAME is the name of the project.

    For example:

    git clone ssh://user@gmail.com@source.developers.google.com:2022/p/example-project/r/test-repo
    

The first time you connect to Cloud Source Repositories using SSH, you are asked to confirm the SSH key fingerprints for the remote host. The hostname for the repository service is source.developers.google.com. The fingerprints are:

SHA256:AGvEpqYNMqsRNIviwyk4J4HM0lEylomDBKOWZsBn434
MD5:74:84:6c:08:d5:b5:54:68:19:da:2a:8e:4c:5b:d3:0d

What's next

After you clone a repository to your local machine, you can:

  • Explore the quickstarts to learn how Cloud Source Repositories integrates with other Google Cloud Platform services.
หน้านี้มีประโยชน์ไหม โปรดแสดงความคิดเห็น