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.
- In GCP console, on the top right toolbar, click the Open Cloud Shell button.
- Click Continue. It takes a few moments to provision and connect to the environment.
- Make sure you set the project ID before proceeding, please use this command below;
gcloud config set project [PROJECT ID]
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
gcloud source repos create Demo_Repo
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
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:
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 "email@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
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.
View a file in the GCP repository
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! :)