Create a code repository in Cloud Source Repositories
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. 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
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.
- Install the Google Cloud CLI.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- Verify that you have the latest version of Git.
- If you have not configured your user credentials in Git, follow the first time setup instructions.
- Enable the Cloud Source Repositories API.
Create a repository
In a terminal window, use the gcloud source repos create
command to create a
Google Cloud 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
Google Cloud 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.
Go to your
hello-world
repository.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.
Go to your
hello-world
repository.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.
In a terminal window, go to your
hello-world
directory:cd hello-world
Add the files:
git add .
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"
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 theorigin
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
In the Google Cloud console, open Cloud Source Repositories.
Click the name of the
hello-world
repository that you created.Go to the files you pushed to the repository.
The GCP Console shows the files in the
master
branch at the most recent commit.In the Files list, click a file to view its contents.
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.
In the GCP Console, open the All repositories page for Cloud Source Repositories.
Hold the pointer over the repository you want to delete and click Settings settings.
The General settings page opens.
Click Delete this repository delete.
The Remove repository dialog opens.
Type the name of the repository you want to delete.
Click Delete.
What's next
- Learn more about setting up a repository.
- Learn more about cloning a repository.
- Learn how to add a repository as a Git remote.
- Learn how to connect a repository hosted on GitHub or Bitbucket.