建立空的存放區

您可以使用 Cloud Source Repositories 建立新的空存放區。如要使用 Cloud Source Repositories 啟動專案或備份 Git 存放區,建立存放區會很有幫助。

事前準備

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

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

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  5. Make sure that billing is enabled for your Google Cloud project.

  6. Install the Google Cloud CLI.

  7. If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.

  8. To initialize the gcloud CLI, run the following command:

    gcloud init
  9. 確認您有最新版本的 Git
  10. 如果您尚未在 Git 中設定使用者憑證,請按照 首次設定操作說明進行設定。
  11. 啟用 Cloud Source Repositories API。
  12. 啟用 Cloud Source Repositories API

    建立新的存放區

    您可以使用 Google Cloud 主控台或 gcloud 指令列工具建立存放區。

    主控台

    1. 在 Google Cloud 控制台中,開啟 Cloud Source Repositories。

      開啟 Cloud Source Repositories

    2. 按一下「新增存放區」

      「新增存放區」頁面隨即開啟。

    3. 選擇「建立新的存放區」,然後按一下「繼續」

      「建立新存放區」頁面隨即開啟。

    4. 在「存放區名稱」欄位中,輸入新存放區的名稱。 請注意,All-UsersAll-Projects 是受限名稱,無法使用。

    5. 在「專案」下拉式清單中,選取存放區所屬的 Google Cloud專案。

      如要建立新專案 Google Cloud ,請按一下「建立專案」

    6. 點選「建立」

      系統會建立存放區,並開啟「Add code to your repository」(將程式碼新增至存放區) 頁面。本頁提供操作說明,說明如何根據驗證類型將存放區複製到本機電腦,或從現有存放區推送程式碼

    gcloud

    1. 從指令列呼叫:

      gcloud init
      gcloud source repos create [REPO_NAME]
      

      其中 [REPO_NAME] 是存放區的名稱。請注意,All-UsersAll-Projects 是受限制的名稱,不得使用。

    建立專案

    所有存放區都必須屬於 Google Cloud 專案。如果沒有 Google Cloud 專案,請按照下列步驟建立。

    1. 在「Create new repository」(建立新存放區)頁面中,按一下「Create project」(建立專案)

      「建立 Cloud 專案」對話方塊隨即開啟。

    2. 在「專案名稱」欄位中,輸入專案名稱。 Google Cloud

    3. 在「專案 ID」欄位中,接受產生的專案 ID,或按一下「編輯專案 ID」輸入其他 ID。

    4. 在「帳單帳戶」下拉式清單中,選取帳單帳戶。

      如要建立帳單帳戶,請按一下「建立帳單帳戶」

    5. 點選「建立」

    您可以繼續建立新存放區

    後續步驟

    在 Cloud Source Repositories 中有了存放區後,您現在可以新增程式碼,這可能涉及下列任一程序: