Adding a repository as a remote

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

Before you begin

  1. Select or create a GCP project.

    Go to the project selector 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. On Linux or macOS, run the credential helper script:

    git config --global credential.''.helper

    Or on Windows:

    git config --global credential. 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.

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

  3. Create the repository in Cloud Source Repositories:

    gcloud source repos create [CLOUD_SOURCE_REPOSITORY_NAME]
  4. Add a repository as a remote:

    git remote add google \[PROJECT_ID]/r/[CLOUD_SOURCE_REPOSITORY_NAME]

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

Generating static credentials

In some cases, you might not have access to the Cloud SDK. For example, you might work on a build server that does not have access to these tools. In these situations, you can manually generate static credentials.

  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. Change the preferred authentication method to manually generated credentials.

  5. Follow the instructions to use the generated credentials.

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.

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
Cloud Source Repositories Documentation