您可以使用 Cloud Source Repositories 建立新的空存放區。如要使用 Cloud Source Repositories 啟動專案或備份 Git 存放區,建立存放區會很有幫助。
事前準備
- 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.
-
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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
- 確認您有最新版本的 Git。
- 如果您尚未在 Git 中設定使用者憑證,請按照 首次設定操作說明進行設定。
- 啟用 Cloud Source Repositories API。
在 Google Cloud 控制台中,開啟 Cloud Source Repositories。
按一下「新增存放區」。
「新增存放區」頁面隨即開啟。
選擇「建立新的存放區」,然後按一下「繼續」。
「建立新存放區」頁面隨即開啟。
在「存放區名稱」欄位中,輸入新存放區的名稱。 請注意,
All-Users
和All-Projects
是受限名稱,無法使用。在「專案」下拉式清單中,選取存放區所屬的 Google Cloud專案。
如要建立新專案 Google Cloud ,請按一下「建立專案」。
點選「建立」。
系統會建立存放區,並開啟「Add code to your repository」(將程式碼新增至存放區) 頁面。本頁提供操作說明,說明如何根據驗證類型將存放區複製到本機電腦,或從現有存放區推送程式碼。
從指令列呼叫:
gcloud init gcloud source repos create [REPO_NAME]
其中
[REPO_NAME]
是存放區的名稱。請注意,All-Users
和All-Projects
是受限制的名稱,不得使用。在「Create new repository」(建立新存放區)頁面中,按一下「Create project」(建立專案)。
「建立 Cloud 專案」對話方塊隨即開啟。
在「專案名稱」欄位中,輸入專案名稱。 Google Cloud
在「專案 ID」欄位中,接受產生的專案 ID,或按一下「編輯專案 ID」輸入其他 ID。
在「帳單帳戶」下拉式清單中,選取帳單帳戶。
如要建立帳單帳戶,請按一下「建立帳單帳戶」。
點選「建立」。
- 將新存放區複製到本機電腦。
- 從本機電腦上的現有存放區推送程式碼。
啟用 Cloud Source Repositories API
建立新的存放區
您可以使用 Google Cloud 主控台或 gcloud
指令列工具建立存放區。
主控台
gcloud
建立專案
所有存放區都必須屬於 Google Cloud 專案。如果沒有 Google Cloud 專案,請按照下列步驟建立。
您可以繼續建立新存放區。
後續步驟
在 Cloud Source Repositories 中有了存放區後,您現在可以新增程式碼,這可能涉及下列任一程序: