Adding a Repository as a Remote

You can add a Cloud Source Repository as 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 Projects 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:

  2. Run the credential helper script (on Linux or Mac OS X):

    git config credential.helper

    Or on Windows:

    git config credential.helper gcloud.cmd

    The credential helper scripts provide the information needed by Git to connect securely to the Cloud Source Repository 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.

  3. Add the Cloud Source Repository as a remote:

    git remote add google[PROJECT_ID]/

    where [PROJECT_ID] is the ID of your Cloud Platform project.

Cloning a repository

As an alternative, you can also create a new local Git repository by cloning the contents of an existing Cloud Source Repository:

gcloud init
gcloud source repos clone [REPO_NAME] [LOCAL_DIRECTORY]

The gcloud source repos clone command adds the Cloud Source Repository as a remote named origin and clones it into a local Git repository located in [LOCAL_DIRECTORY].

Note for MacOS users: When using a tool for your git operations that does not include gcloud in the path, you will need to qualify your clone command with the full gcloud path for the credential helper to work. Using the full path to gcloud means that gcloud does not need to be in the path for future git operations on the repository.

gcloud beta source repos clone --use-full-gcloud-path [REPO_NAME] [LOCAL_DIRECTORY]

Using the repository as a remote

A Cloud Source Repository is a fully-featured Git repository. You can use the standard set of Git commands to interact with the repository, including push, pull, clone and log.

Pushing to a Cloud Source Repository

To push from your local Git repository to the Cloud Source Repository:

git push google master

Pulling from a Cloud Source Repository

To pull from the Cloud Source Repository to your local Git repository:

git pull google master

Viewing the commit history from a Cloud Source Repository

To view the commit history:

git log google/master

What's next

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

Monitor your resources on the go

Get the Google Cloud Console app to help you manage your projects.

Send feedback about...

Cloud Source Repositories