You can use Cloud Source Repositories to add a Google Cloud repository as a remote to a local Git repository.
Before you begin
In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
- Install Git.
- Install and initialize the Cloud SDK.
Add the repository as a remote
Change your current working directory to the directory that contains your local Git repository:
[REPO_DIRECTORY]is the path to your repository.
On Linux or macOS, run the credential helper script:
Linux or macOS
git config --global credential.'https://source.developers.google.com'.helper gcloud.sh
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
sshkeys) to establish this secure connection.
Create the repository in Cloud Source Repositories:
gcloud source repos create [REPO_NAME]
[REPO_NAME]is the name for your Google Cloud repository.
Add a repository as a remote:
git remote add google \ https://source.developers.google.com/p/[PROJECT_ID]/r/[REPO_NAME]
[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 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 Cloud SDK. 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.
In the Google Cloud Console, open Cloud Source Repositories.
Hold the pointer over the repository you want to clone.
Click Clone add_box.
A dialog with authentication options opens.
Click the Manually generated credentials tab and follow the instructions to clone your repository.
After you have pushed source files to Cloud Source Repositories, you can view repository files from within the GCP Console.