Adding a Repository as a Remote

You can use Google Cloud Source Repositories to add a remote to a local Git repository and use it in the same way you use other Git remotes.

Before you begin

  1. Select or create a Cloud Platform project.

    Go to the Manage resources page

  2. Install Git.
  3. Install and initialize the Cloud SDK.

Adding the repository as a remote

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

    cd [REPO_DIRECTORY]
    
  2. Run the credential helper script (on Linux or MacOS X):

    git config credential.helper gcloud.sh
    

    Or on Windows:

    git config credential.helper gcloud.cmd
    

    The credential helper scripts provide the information needed by Git 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.

    Note that the gcloud command-line tool must be in your $PATH for the credential helper scripts to work.

    If you cannot use the gcloud tool (e.g. you are on a build server)

    You may use static credentials by manually generating them in the cloud-console.

    • Go to the repository page and click the clone button, then change the preferred authentication method to manually generated credentials and follow the instructions to use the generated credentials.
  3. Add a repository as a remote:

    gcloud source repos create [YOUR_REPO]
    git remote add google\
    https://source.developers.google.com/p/[PROJECT_ID]/r/[YOUR_REPO]
    

    where [PROJECT_ID] is the ID of your Cloud Platform project and [YOUR_REPO] is the name of your Cloud Source Repository.

Using the repository as a remote

GCP 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.

Pushing to a GCP repository:

To push from your local Git repository to a GCP repository:

git push google master

Pulling from a GCP repository

To pull from a GCP repository to your local Git repository:

git pull google master

Viewing the commit history of a GCP repository

To view the commit history:

git log google/master

What's next

After you have pushed source files to Cloud Source Repositories, you can view repository files from within the Google Cloud Platform Console.

Send feedback about...

Cloud Source Repositories