Adding a repository as a remote

You can use Cloud Source Repositories to add a Google Cloud repository as a remote to a local Git repository.

Before you begin

  1. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  2. Install Git .
  3. Install the Google Cloud CLI. After installation, initialize the Google Cloud CLI by running the following command:

    gcloud  
    init

    If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity .

Add the repository as a remote

  1. Change your current working directory to the directory that contains your local Git repository:

      cd 
      
     [ 
     REPO_DIRECTORY 
     ] 
     
    

    Where [REPO_DIRECTORY] is the path to your repository.

  2. On Linux or macOS, run the credential helper script:

    Linux or macOS

     git config --global credential.'https://source.developers.google.com'.helper gcloud.sh 
    

    Windows

     git config --global credential.https://source.developers.google.com.helper gcloud.cmd 
    

    Credential helper scripts provide the information that Git needs to connect securely to Cloud Source Repositories using your Google Account credentials. You don't need to perform any additional configuration steps (for example, uploading ssh keys) to establish this secure connection.

  3. Create the repository in Cloud Source Repositories:

      gcloud 
      
     source 
      
     repos 
      
     create 
      
     [ 
     REPO_NAME 
     ] 
     
    

    Where [REPO_NAME] is the name for your Google Cloud repository.

  4. Add a repository as a remote:

      git 
      
     remote 
      
     add 
      
     google 
      
     \ 
     https 
     : 
     // 
     source 
     . 
     developers 
     . 
     google 
     . 
     com 
     / 
     p 
     /[ 
     PROJECT_ID 
     ]/ 
     r 
     /[ 
     REPO_NAME 
     ] 
     
    

    Where:

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

Use the repository as a remote

Google Cloud repositories are fully featured Git repositories. You can use the standard set of Git commands to interact with these repositories, including push , pull , clone , and log .

Push to a Google Cloud repository

To push from your local Git repository to a Google Cloud repository, enter this command:

 git push google master 

Pull from a Google Cloud repository

To pull from a Google Cloud repository to your local Git repository, enter this command:

 git pull google master 

View the commit history of a Google Cloud repository

To view the commit history, enter this command:

 git log google/master 

Generate static credentials

In some cases, you might not have access to the gcloud CLI. For example, you might work on a build server that doesn't have access to these tools. In these situations, you can manually generate static credentials.

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

    Open Cloud Source Repositories

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

  3. Click Clone .

    A dialog with authentication options opens.

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

What's next

Design a Mobile Site
View Site in Mobile | Classic
Share by: