

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 連接 Git 儲存庫 (AWS CLI)
<a name="studio-updated-git-attach-cli"></a>

本節說明如何使用 連接 Git 儲存庫 （儲存庫） URL AWS CLI。連接 Git 儲存庫 URL 後，您可以遵循[複製 Amazon SageMaker Studio 中的 Git 儲存庫](#studio-updated-tasks-git)中的步驟複製它。

## 先決條件
<a name="studio-updated-git-attach-cli-prerequisites"></a>

開始之前，請先完成以下先決條件：
+  AWS CLI 按照[安裝目前 AWS Command Line Interface 版本](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv1.html#install-tool-bundled)中的步驟更新 。
+ 從您的本機機器，執行 `aws configure` 並提供您的 AWS 憑證。如需 AWS 登入資料的相關資訊，請參閱[了解並取得您的 AWS 登入](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html)資料。
+ 加入 Amazon SageMaker AI 網域。如需詳細資訊，請參閱[Amazon SageMaker AI 網域概觀](gs-studio-onboard.md)。

## 將 Git 儲存庫連接至 Amazon SageMaker AI 網域 (網域) 或使用者設定檔
<a name="studio-updated-git-attach-cli-attach"></a>

所有使用者都會繼承與網域層級關聯的 Git 儲存庫 URL。不過，在使用者設定檔層級關聯的 Git 儲存庫 URL 會限定為特定使用者。您可以傳遞儲存庫 URL 清單，將多個 Git 儲存庫 URL 連接至 Amazon SageMaker AI 網域或使用者設定檔。

以下各節說明如何將 Git 儲存庫 URL 連接至您的網域和使用者設定檔。

### 連接至 Amazon SageMaker AI 網域
<a name="studio-updated-git-attach-cli-attach-domain"></a>

下列命令將 Git 儲存庫 URL 連接至現有網域。

```
aws sagemaker update-domain --region {{region}} --domain-id {{domain-id}} \
    --default-user-settings JupyterLabAppSettings={CodeRepositories=[{RepositoryUrl="{{repository}}"}]}
```

### 連接至使用者設定檔
<a name="studio-updated-git-attach-cli-attach-userprofile"></a>

下列命令將 Git 儲存庫 URL 連接至現有的使用者設定檔。

```
aws sagemaker update-user-profile --domain-id {{domain-id}} --user-profile-name {{user-name}}\
    --user-settings JupyterLabAppSettings={CodeRepositories=[{RepositoryUrl="{{repository}}"}]}
```

## 複製 Amazon SageMaker Studio 中的 Git 儲存庫
<a name="studio-updated-tasks-git"></a>

Amazon SageMaker Studio 只能連接至本機 Git 儲存庫。若要存取儲存庫中的檔案，請從 Studio 內複製 Git 儲存庫。若要這樣做，Studio 會提供一個 Git 延伸模組，讓您輸入 Git 儲存庫的 URL、將其複製到您的環境、推送變更，以及檢視遞交歷程記錄。

如果儲存庫是私有且需要憑證才能存取，則您會收到輸入使用者憑證的提示。您的憑證包含使用者名稱和個人存取權杖。如需有關個人存取權杖的更多相關資訊，請參閱[管理您的個人存取權杖](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens)。

管理員也可以在 Amazon SageMaker AI 網域或使用者設定檔層級連接建議的 Git 儲存庫 URL。使用者可以從建議清單中選擇儲存庫 URL，並將其複製到 Studio 中。如需關於連接建議的更多相關資訊，請參閱 [將建議的 Git 儲存庫連接至 Amazon SageMaker Studio Classic](studio-git-attach.md)。