Quickstart: Create a repository

In this quickstart, you create a repository in Cloud Source Repositories. You then commit the code for a small Python app that you can deploy later to App Engine.

Cloud Source Repositories are private Git repositories hosted on Google Cloud Platform (GCP). These repositories let you develop and deploy an app or service in a space that provides collaboration and version control for your code.

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 project selector page

  3. Make sure that billing is enabled for your Google Cloud Platform project. Learn how to enable billing.

  4. Install and initialize the Cloud SDK.
  5. Verify that you have the latest version of Git.
  6. Enable the Cloud Source Repositories API.
  7. Enable the Cloud Source Repositories API

Create a repository

In a terminal window, use the gcloud source repos create command to create a GCP repository named hello-world:

gcloud source repos create hello-world

Clone a repository

Use the gcloud source repos clone command to clone the contents of the GCP repository into a local Git repository:

gcloud source repos clone hello-world

Create a "Hello, World!" script

Create a Python script that prints Hello, World! in a browser window.

  1. Go to your hello-world repository.

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

    #!/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

Create an app.yaml file that contains the configuration information you need to deploy your code to App Engine.

  1. Go to your hello-world repository.

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

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

Push to Cloud Source Repositories

Push the files you just created into Cloud Source Repositories.

  1. In a terminal window, go to your hello-world directory:

    cd hello-world
    
  2. Add the files:

    git add .
    
  3. Commit the files to the repository with a comment describing the history of this action:

    git commit -m "Add Hello World app to Cloud Source Repositories"
    
  4. Using the git push command, add the contents of the local Git repository to Cloud Source Repositories:

    git push origin master
    

    Git pushes the files from the master branch to the origin remote. Output similar to the following is displayed:

    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
    

View files in the repository

  1. In the Google Cloud Platform Console, open Cloud Source Repositories.

    Open Cloud Source Repositories

  2. Click the name of the hello-world repository that you created.

  3. Go to the files you pushed to the repository.

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

  4. In the Files list, click a file to view its contents.

    Screenshot that shows the Files list in Cloud Source Repositories

You can also view the files by using Cloud Shell.

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're finished with this repository, you can delete it by following these steps.

  1. In the GCP Console, open the All repositories page for Cloud Source Repositories.

    Open Cloud Source Repositories

  2. Hold the pointer over the repository you want to delete and click Settings .

    The General settings page opens.

  3. Click Delete this repository .

    The Remove repository dialog opens.

  4. Type the name of the repository you want to delete.

  5. Click Delete.

What's next

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

Send feedback about...

Cloud Source Repositories Documentation