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 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 Cloud Source Repositories API.

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 Cloud Source Repositories in the console:

    Open Cloud Source Repositories

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

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

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

You can also view the files 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 are finished with this repository, you can delete it by following these steps:

  1. Open the All Repositories view for Cloud Source Repositories:

    Open Cloud Source Repositories

  2. Hover over the repository and click the Gear button.

    The General Settings screen opens.

  3. Click Delete This Repository.

    The Remove Repository screen opens.

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

  5. Click Delete.

What's next

Trang này có hữu ích không? Hãy cho chúng tôi biết đánh giá của bạn:

Gửi phản hồi về...

Cloud Source Repositories Documentation