You can use Cloud Source Repositories to create a new, empty repository. Creating a
repository is useful when you want to start a project or back up a Git
repository using Cloud Source Repositories.

## Before you begin

1.
   [Install](https://docs.cloud.google.com/sdk/docs/install) the Google Cloud CLI.

2. If you're using an external identity provider (IdP), you must first
   [sign in to the gcloud CLI with your federated identity](https://docs.cloud.google.com/iam/docs/workforce-log-in-gcloud.md.txt).

3.
   To [initialize](https://docs.cloud.google.com/sdk/docs/initializing) the gcloud CLI, run the following command:

   ```bash
   gcloud init
   ```
4. [Verify that you have the latest version of Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git).
5. If you have not configured your user credentials in Git, follow the [first time setup instructions.](https://git-scm.com/book/en/v2/Getting-Started-First-Time-Git-Setup)
6. Enable the Cloud Source Repositories API.
7. [Enable the Cloud Source Repositories API](https://console.cloud.google.com/apis/enableflow?apiid=sourcerepo.googleapis.com&redirect=https://cloud.google.com/source-repositories/docs/creating-an-empty-repository)

## Create a new repository

You can create a repository by using either the Google Cloud console or the `gcloud`
command-line tool.

### Console

1. In the Google Cloud console, open Cloud Source Repositories.

   [Open Cloud Source Repositories](https://source.cloud.google.com/repos)
2. Click **Add repository**.

   The **Add a repository** page opens.
3. Select **Create new repository** and click **Continue**.

   The **Create new repository** page opens.
4. In the **Repository name** field, type a name for the new repository.
   Note that the names `All-Users` and `All-Projects` are restricted names
   and cannot be used.

5. In the **Project** drop-down list, select the Google Cloud
   project the repository belongs to.

   To [create a new Google Cloud project](https://docs.cloud.google.com/source-repositories/docs/creating-an-empty-repository.md.txt#create_a_project), click
   **Create project**.
6. Click **Create**.

   Your repository is created, and the **Add code to your repository** page
   opens. This page provides instructions on how to
   [clone the repository to your local machine](https://docs.cloud.google.com/source-repositories/docs/cloning-repositories.md.txt)
   or
   [push code from an existing repository](https://docs.cloud.google.com/source-repositories/docs/pushing-code-from-a-repository.md.txt)
   based on your authentication type.

### gcloud

1. From the command line, call:

       gcloud init
       gcloud source repos create [REPO_NAME]

   Where `[REPO_NAME]` is the name for your repository. Note that the names
   `All-Users` and `All-Projects` are restricted names and cannot be used.

## Create a project

All repositories must belong to a Google Cloud project. If you don't have
a Google Cloud project, you can create one by following these steps.

1. On the **Create new repository** [page](https://docs.cloud.google.com/source-repositories/docs/creating-an-empty-repository.md.txt#create_a_new_repository), click
   **Create project**.

   The **Create Cloud project** dialog opens.
2. In the **Project name** field, type a name for the Google Cloud
   project.

3. In the **Project ID** field, either accept the generated project ID or click
   **Edit Project ID** to enter a different one.

   > [!NOTE]
   > **Note:** Your Google Cloud project ID must be unique across Google Cloud.

4. In the **Billing Account** drop-down list, select a billing account.

   To create a billing account, click **Create billing account**.
5. Click **Create**.

You can continue [creating a new repository](https://docs.cloud.google.com/source-repositories/docs/creating-an-empty-repository.md.txt#create_a_new_repository).

## What's next

Now that you have a repository in Cloud Source Repositories, you can now add
your code, which might involve either of these processes:

- [Cloning your new repository](https://docs.cloud.google.com/source-repositories/docs/cloning-repositories.md.txt) to your local machine.
- [Pushing code from an existing repository](https://docs.cloud.google.com/source-repositories/docs/pushing-code-from-a-repository.md.txt) on your local machine.