Quick Tour to Google Cloud Source repository

Mehul Patel
Apr 30, 2020 · 4 min read

In this blog, you will learn about the Google Cloud Source Repositories, which gives Git version control to support the collaborative development of any application or service.

In this practice, we will build a local Git repository that includes a sample file, add a Google Source Repository as a remote, and push the contents of the local repository. We will use Google Cloud Platform Console to perform these operations.

I have used Google Qwiklabs credits to perform this practice. Thank you Google. 🙌

Activate Google Cloud Shell

Google Cloud Shell is a virtual machine that is loaded with development tools. It allows a persistent 5GB home directory and works on the Google Cloud. Google Cloud Shell gives a command-line way to your GCP resources.

  1. In GCP console, on the top right toolbar, click the Open Cloud Shell button.

Note: gcloud is the command-line tool for Google Cloud Platform. It comes pre-installed on Cloud Shell and supports tab-completion.

Step I: Create a new repository

Begin a new session in Cloud Shell and run the following command to create a new Cloud Source Repository named Demo_Repo:

gcloud source repos create Demo_Repo
You can safely ignore any billing warnings for creating repositories. Please check out the this Doc for complete billing guide.

Step II: Clone the new repository into your Cloud Shell session

Clone the contents of your fresh Cloud Source Repository to a local repo in your Cloud Shell session:

gcloud source repos clone Demo_Repo

The gcloud source repos clone command adds Cloud Source Repositories as a remote named origin and clones it into a local Git repository.

Step III: Push to the Cloud Source Repository

Go into the local repository you created:

cd Demo_Repo

Run the following command to create a file demofile.txt(name the file as you wish) in your local repository with text message.

echo "Hello Google Cloud!" > demofile.txt

Commit the file using the following Git commands:

git config --global user.email "you@example.com"git config --global user.name "Your Name"git add demofile.txtgit commit -m "This is my first demo file using Cloud Source Repositories" demofile.txt

Once you’ve committed code to the local repository, use the git push command to add its contents to Cloud Source Repositories.

git push origin master

Git pushes the current folder contents (demofile.txt) from the master branch to the origin remote:

Step IV: 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 files you pushed to the repository by opening the Navigation menu and selecting Source Repositories > Source Code.

The console shows the files in the master branch at the most recent commit.

View a file in the GCP repository

Click Demo_Repo > demofile.txt to view the file's contents in the source code browser:

Want to know some exclusive Git commands?, Please refer this blog.

Thank you for reading! :)

TechnoPanti

Absorb the future tech!

TechnoPanti

TechnoPanti is an online platform focusing on the tech industry and posts the useful out-of-the-box articles for aspirants like you and me.

Mehul Patel

Written by

Tech Speaker | Linux Engineer | DevOps | OpenSource Enthusiast | Independent Researcher | Technical Writer | Explorer

TechnoPanti

TechnoPanti is an online platform focusing on the tech industry and posts the useful out-of-the-box articles for aspirants like you and me.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store