Pushing Code from an Existing Repository

This topic describes how to push code from an existing repository on your local machine to Cloud Source Repositories.

Before you begin

You must have a repository in Cloud Source Repositories. To create a new repository, see Creating an Empty Repository.

Pushing a local repository into Cloud Source Repositories

You can push a local repository to Cloud Source Repositories using either the Google Cloud SDK or manually generated credentials.

Google Cloud SDK

  1. Open a terminal window.

  2. Install the Google Cloud SDK.

  3. If you're using Windows, type the following command.

    gcloud init && git config credential.helper gcloud.cmd
    

    If you're using a Linux or macOS, type the following command.

    gcloud init && git config credential.helper gcloud.sh
    
  4. Type the following command to add your local repository as a remote.

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

    Where:

    • [PROJECT_NAME] is the name of your project
    • [REPOSITORY_NAME] is the name of your repository
  5. Type the following command to push your code to Cloud Source Repositories.

    git push --all google
    

Manual

  1. Generate and store your Git credentials.

  2. Open a terminal window.

  3. Type the following command to add your local repository as a remote.

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

    Where:

    • [PROJECT_NAME] is the name of your project
    • [REPOSITORY_NAME] is the name of your repository
  4. Type the following command to push your code to Cloud Source Repositories.

    git push --all google
    

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 push your local repository to your local machine, you can:

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Source Repositories