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 thencd
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.
- Configure two variables
user.email
anduser.name
. - Add the file:
git add greetings.txt
- Commit the file:
git commit -m "Committed initial file" greetings.txt
- Configure two variables
- Push the file from the master branch to origin.
Use the command:
git push origin master
- Confirm the operation.
- From the Source Repositories dashboard, click the
gcpro_repo
repo. - Click the
greetings.txt
file to review the contents.
- From the Source Repositories dashboard, click the
- 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.
- From the Source Repository dashboard, click Add repository.
- In the "Add a Repository" dialog, choose Connect external repository.
- On the Connect External Repository page, select the current project and then, from the Git Provider list, choose GitHub.
- When the Consent checkbox appears, select it.
- Choose Connect to GitHub.
- From the list of your repos, select one.
- Click Connect selected repository.
- Confirm the operation.
When the files of the repo are displayed, select one to open and confirm its contents.