Quickstart for Creating a New Repository

Google Cloud Source Repositories provides Git version control to support collaborative development of an application or service, such as those that run on App Engine and Compute Engine.

This page shows you how to create a new repository in Cloud Source Repositories. This repository will contain a simple Python application you can later deploy to App Engine.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a GCP project.

    Go to the Manage resources page

  3. Make sure that billing is enabled for your project.

    Learn how to enable billing

  4. Install and initialize the Cloud SDK.
  5. Install Git.

Create a new repository

From a terminal window, create a new Google Cloud Platform (GCP) repository, named hello-world, using the gcloud source repos create command:

gcloud source repos create hello-world

Clone a repository

Clone the contents of the GCP repository into a local Git repository using the gcloud source repos clone command:

gcloud source repos clone hello-world

Create a Hello World script

In this step you create a Python script that prints Hello, world! in a browser window.

  1. Navigate to your hello-world repository.

  2. Using a text editor, create a file named main.py and paste the following:

    #!/usr/bin/env python
    
    import webapp2
    
    class MainHandler(webapp2.RequestHandler):
        def get(self):
            self.response.write('Hello world!')
    
    app = webapp2.WSGIApplication([
        ('/', MainHandler)
    ], debug=True)
    

Create an app.yaml file

In this step you create an app.yaml file. You use this file to deploy code to App Engine.

  1. Navigate to your hello-world repository.

  2. Using a text editor, create a file named app.yaml and paste the following:

    runtime: python27
    api_version: 1
    threadsafe: yes
    
    handlers:
    - url: .*
      script: main.app
    
    libraries:
    - name: webapp2
      version: "2.5.2"
    

Push to Cloud Source Repositories

In this step, you push the files you just created into Cloud Source Repositories.

  1. Add the files:

    git add .
    
  2. Commit the file:

    git commit -m "Add Hello World app to Cloud Source Repositories"
    
  3. Add the contents of the local Git repository to Cloud Source Repositories using the git push command:

    git push origin master
    

    Git pushes the files from the master branch to the origin remote. You should see output similar to the following:

    Counting objects: 21, done.
    Delta compression using up to 6 threads.
    Compressing objects: 100% (20/20), done.
    Writing objects: 100% (21/21), 9.76 KiB | 0 bytes/s, done.
    Total 21 (delta 5), reused 0 (delta 0)
    remote: Storing objects: 100% (21/21), done.
    remote: Processing commits: 100% (6/6), done.
    To https://source.developers.google.com/p/example-project-1244/r/repo-name
     * [new branch]      master -> master
    

Browse and view files in the repository

  1. Open the Source view in the GCP Console:

    Open the Source View in the Console

  2. Browse to the files you pushed to the repository. The console shows the files in the master branch at the most recent commit.

  3. View a file by clicking its contents in the source code browser.

Clean up

With your hello-world repository in place, you can continue to explore Cloud Source Repositories. For a complete list of available quickstarts, see Quickstarts.

If you are finished with this repository, you can delete it by following these steps:

  1. Open the source view in the GCP Console:

    Open the Source View in the Console

  2. Click the More button More button next to the repository you want to delete.

    Create Repository button

  3. Select Delete.

  4. When prompted for the repository name, enter hello-world and then click Delete.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Source Repositories