Google Cloud Source Repositories provides Git version control to support collaborative development of any application or service. In this lab, you will create a local Git repository that contains a sample file, add a Google Source Repository as a remote, and push the contents of the local repository. You will use the source browser included in Source Repositories to view your repository files from within the Cloud Console.
Create a new repository
Start a new session in Cloud Shell and run the following command to create a new Cloud Source Repository named
gcloud source repos create REPO_DEMO
You can safely ignore any billing warnings for creating repositories.
Clone the new repository into your Cloud Shell session
Clone the contents of your new Cloud Source Repository to a local repo in your Cloud Shell session:
gcloud source repos clone REPO_DEMO
gcloud source repos clone command adds Cloud Source Repositories as a remote named origin and clones it into a local Git repository.
Push to the Cloud Source Repository
Go into the local repository you created:
Run the following command to create a file
myfile.txt in your local repository:
echo 'Hello World!' > myfile.txt
Commit the file using the following Git commands:
git config --global user.email "firstname.lastname@example.org"
git config --global user.name "Your Name"
git add myfile.txt
git commit -m "First file using Cloud Source Repositories" myfile.txt
Your output should resemble the following:
Once you’ve committed code to the local repository, add its contents to Cloud Source Repositories using the
git push command:
git push origin master
Git pushes the sample application files from the
master branch to the
Browse files in the Google Cloud Source repository
Use the Google Cloud Source Repositories source code browser to view repository files. You can filter your view to focus on a specific branch, tag, or comment.
Browse the sample files you pushed to the repository by opening the Navigation menu and selecting Source Repositories.
The console shows the files in the master branch at the most recent commit.
View a file in the Google Cloud repository
myfile.txt to view the file’s contents in the source code browser:
Click on myfile.txt