Developing on GCP 💻 - Managing Source Codes with Cloud Source Repositories 📁

Google Cloud Source Repositories

Google Cloud Source Repositories is a single place for your team to store, manage, and track code. Cloud Source Repositories allows developers to collaborate easily and more securely manage your code on a fully featured, scalable, private Git repository. It can also be extended by connecting to other GCP tools, including Cloud Build, App Engine, Stackdriver, and Cloud Pub/Sub. Cloud Source Repositories enables fast, indexed powerful code search across all your owned repositories to save time.

We'll be focusing on using Google Cloud Source Repositories to manage source codes during development and exploring some of its features that aids in improving developers productivity.

Benefits of using Google Cloud Source Repositories

Unlimited private Git repositories

Get free unlimited private repositories to organize your code in a way that works best for you. Mirror code from GitHub or Bitbucket repositories to get powerful code search, code browsing, and diagnostics capabilities. Cloud Source Repositories allows developers to create up to 1,000 repositories per Google Cloud Platform project.

Integrate with GCP services

Get fast feedback on your code changes with built-in integrations for continuous integration. You can easily set up triggers to automatically build and test using Cloud Build when you push changes to Cloud Source Repositories.

Use powerful regexp to search across multiple directories. You can use regular expressions to refine your search or perform a single targeted search across projects, files, and code repositories. Cloud Source Repositories uses the same search technologies like Google Search but optimizes the indexing algorithms.

Screenshot from 2019-06-29 17-49-44.png

Source browser

View repository files from within the Cloud Source Repositories using Source Browser. Filter your view to focus on a specific branch, tag, or commit.

Automatic syncing with across hosted repositories

Connect Cloud Source Repositories to a hosted repository on GitHub or Bitbucket. Automatically sync changes to Cloud Source Repositories when changes are pushed to GitHub or Bitbucket.

Git operations

Basically, you're allowed to use all Git operations e.g. Push, pull, clone and log, and perform other Git operations required by your workflow.

Proven reliability

Manage your code on systems distributed geographically across multiple data centres and being run on Google’s infrastructure with high availability.

Security & Debugging

Cloud Source Repositories has a Push-block feature enabled which checks for secret credentials on your commits and can stop you from pushing such credentials with details. In addition, Stackdriver debugger allows you debug codes on Cloud Source Repositories.

output.png

Setting up a new repository on Cloud Source Repositories

You can use Google Cloud Source Repositories to create a new, empty repository.

On your Cloud Source Repositories dashboard, follow the steps below:

  • Click Add Repository
  • Select Create New Repository and Continue
  • Enter the Repository Name and Select the Project it belongs to.

Screenshot from 2019-06-29 17-36-43.png

Alternatively, you can create a new repository using the cloud command:

gcloud source repos create SampleCodes

Mirroring a repository

As at the time of publishing this article, Cloud Source Repositories supports both GitHub and Bitbucket repositories. By enabling mirroring, commits that you push to GitHub/Bitbucket repositories are copied, or mirrored, into a repository hosted in Cloud Source Repositories.

To mirror a repository, on your Cloud Source Repositories dashboard, follow the steps below:

  • Click Add Repository
  • Select Connect external repository and Continue
  • Select the Project that owns the repository, Git provider you are mirroring from, Authorize and Connect
  • Select a Repository and Click Connect Selected Repository

Screenshot from 2019-06-29 18-38-30.png

Cloning a repository

You must set up authentication in your environment before you can access any hosted repositories from your system. Cloud Source Repositories supports the following types of authentication:

  • SSH
  • Cloud SDK
  • Manually generated credentials

You can read more about the Authentication techniques here

Download and Setup Google Cloud SDK using the steps described here

Once that's done, you can simply clone a Cloud Source Repositories repository using:

gcloud source repos clone SourceCodes --project=my-project

Where SourceCodes is the repository name and my-project is the Project ID.

If you'll like to stick to using the Google Cloud Platform to modify your source codes on Cloud Source Repositories, check out my article - Getting Started with Cloud Shell (Editor) 📝

Thanks for reading through! Let me know if I missed any step, if something didn’t work out quite right for you or if this guide was helpful.

Timothy Olaleke

Learn how to use Google Cloud Platform services by following tutorials on #FullStackGCP.

Write your comment…

Great & elegant article, I like it well..... Thanks

Thank you Yusuf

Reply to this…