Migrating Source Code to a Google Cloud Source Repository

30 minutes
  • 11 Learning Objectives

About this Hands-on Lab

Working with code is an everyday reality for cloud application developers, and Google Cloud provides a service that makes it easy to access your code for Google Cloud projects: Source Repositories.

This hands-on lab is divided into two parts. In the first part of the lab, you’ll create a new Source Repository and populate it with example code using the `git` command. Once you have pushed the code to the repo, you’ll use the Source Repository interface to inspect the files.

In the second part of the lab, you’ll set up another Source Repository to mirror your own existing GitHub repository. Please note it is a prerequisite for this part of the lab to have your own GitHub account and at least one repository.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Enable the Source Repository API.

Use the API Library to find and enable the Google Cloud Source Repository API.

Create a Source Repository.

Use the command:

gcloud source repos create gcpro_repo
Clone the Source Repository.

Use the command:

gcloud source repos clone gcpro_repo
Confirm the cloned repo.

Use the ls command to view the new cloned repo and then cd into that folder.

Create an example file.

Use the echo command to create a new file.

Push the new content to the Source Repository repo.
  1. Configure two variables user.email and user.name.
  2. Add the file: git add greetings.txt
  3. Commit the file: git commit -m "Committed initial file" greetings.txt
Push the file from the master branch to origin.

Use the command:

git push origin master
Confirm the operation.
  1. From the Source Repositories dashboard, click the gcpro_repo repo.
  2. Click the greetings.txt file to review the contents.
Return to the main repository page.

Click Cloud Source Repositories in the upper-left. Return to the main repository page where you have at least one repository.

Create new repository.
  1. From the Source Repository dashboard, click Add repository.
  2. In the "Add a Repository" dialog, choose Connect external repository.
  3. On the Connect External Repository page, select the current project and then, from the Git Provider list, choose GitHub.
  4. When the Consent checkbox appears, select it.
  5. Choose Connect to GitHub.
  6. From the list of your repos, select one.
  7. Click Connect selected repository.
Confirm the operation.

When the files of the repo are displayed, select one to open and confirm its contents.

Additional Resources

This hands-on lab is divided into two parts. The first part, which focuses on using the git command and Google Cloud Shell, has no prerequisites and can be fully completed by anyone. The second part, in which a GitHub repository is mirrored by a Google Source Repository, requires you have an established GitHub account and at least one repository. Please have your GitHub login credentials and name of the repository available before beginning this hands-on lab if you wish to complete it entirely.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?