Cloning a repository

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

Before you begin

The following is required to clone the contents of a repository:

Clone using SSH

If you're not using manually generated credentials or the gcloud CLI, you can clone a repository by using SSH.

Console

  1. In the Google Cloud console, open Cloud Source Repositories.

    Open Cloud Source Repositories

  2. Hold your pointer over the repository you want to clone.

  3. Click Clone .

    A dialog with authentication options opens.

  4. Click the SSH authentication tab and follow the instructions to clone your repository.

gcloud

  1. Ensure that you're authenticated with SSH on your local machine.

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

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

    Where:

    • [EMAIL] is your Google Cloud username.
    • [PROJECT_ID] is the ID of the Google Cloud project where the repository is located.
    • [REPO_NAME] is the name of the repository.

    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 by using SSH, you're 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:

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

Clone using the gcloud CLI

If you're not using SSH or manually generated credentials, you can clone a repository by using the gcloud CLI.

Console

  1. In the Google Cloud console, open Cloud Source Repositories.

    Open Cloud Source Repositories

  2. Hold your pointer over the repository you want to clone.

  3. Click Clone .

    A dialog with authentication options opens.

  4. Click the Google Cloud SDK tab and follow the instructions to clone your repository.

gcloud

  1. Ensure that the gcloud CLI is installed on your local system.

  2. In a terminal window, provide your authentication credentials:

    gcloud init
    
  3. Clone your repository:

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

    Where:

    • [REPO_NAME] is the name of your repository.
    • [PROJECT_NAME] is the name of your Google Cloud project.

    For example:

    gcloud source repos clone test-repo --project=example-project
    

Clone using manually generated credentials

If you're not using SSH or the gcloud CLI, you can clone a repository by using manually generated credentials.

Console

  1. In the Google Cloud console, open Cloud Source Repositories.

    Open Cloud Source Repositories

  2. Hold your pointer over the repository you want to clone.

  3. Click Clone .

    A dialog with authentication options opens.

  4. Click the Manually generated credentials tab and follow the instructions to clone your repository.

gcloud

  1. Ensure that you have generated and stored your Git credentials.

  2. In a terminal window, enter the following command:

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

    Where:

    • [PROJECT_NAME] is the name of your project.
    • [REPO_NAME] is the name of your repository.