

文件 AWS 開發套件範例 GitHub 儲存庫中有更多可用的 [AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)。

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

# CodeCommit AWS SDKs程式碼範例
<a name="codecommit_code_examples"></a>

下列程式碼範例示範如何 AWS CodeCommit 搭配 AWS 軟體開發套件 (SDK) 使用 。

*Actions* 是大型程式的程式碼摘錄，必須在內容中執行。雖然動作會告訴您如何呼叫個別服務函數，但您可以在其相關情境中查看內容中的動作。

**其他資源**
+  **[ CodeCommit 使用者指南](https://docs.aws.amazon.com/codecommit/latest/userguide/welcome.html)** – CodeCommit 的相關詳細資訊。
+ **[CodeCommit API 參考](https://docs.aws.amazon.com/codecommit/latest/APIReference/Welcome.html)** – 所有可用 CodeCommit 動作的詳細資訊。
+ **[AWS 開發人員中心](https://aws.amazon.com/developer/code-examples/?awsf.sdk-code-examples-product=product%23)** – 您可以依類別或全文搜尋篩選的程式碼範例。
+ **[AWS SDK 範例](https://github.com/awsdocs/aws-doc-sdk-examples)** – GitHub 儲存庫使用慣用語言的完整程式碼。包含設定和執行程式碼的指示。

**Contents**
+ [基本概念](codecommit_code_examples_basics.md)
  + [動作](codecommit_code_examples_actions.md)
    + [`BatchGetRepositories`](codecommit_example_codecommit_BatchGetRepositories_section.md)
    + [`CreateBranch`](codecommit_example_codecommit_CreateBranch_section.md)
    + [`CreateRepository`](codecommit_example_codecommit_CreateRepository_section.md)
    + [`DeleteRepository`](codecommit_example_codecommit_DeleteRepository_section.md)
    + [`GetBranch`](codecommit_example_codecommit_GetBranch_section.md)
    + [`GetRepository`](codecommit_example_codecommit_GetRepository_section.md)
    + [`ListBranches`](codecommit_example_codecommit_ListBranches_section.md)
    + [`ListRepositories`](codecommit_example_codecommit_ListRepositories_section.md)
    + [`UpdateDefaultBranch`](codecommit_example_codecommit_UpdateDefaultBranch_section.md)
    + [`UpdateRepositoryDescription`](codecommit_example_codecommit_UpdateRepositoryDescription_section.md)
    + [`UpdateRepositoryName`](codecommit_example_codecommit_UpdateRepositoryName_section.md)

# CodeCommit AWS SDKs的基本範例
<a name="codecommit_code_examples_basics"></a>

下列程式碼範例示範如何 AWS CodeCommit 搭配 AWS SDKs 使用 的基本概念。

**Contents**
+ [動作](codecommit_code_examples_actions.md)
  + [`BatchGetRepositories`](codecommit_example_codecommit_BatchGetRepositories_section.md)
  + [`CreateBranch`](codecommit_example_codecommit_CreateBranch_section.md)
  + [`CreateRepository`](codecommit_example_codecommit_CreateRepository_section.md)
  + [`DeleteRepository`](codecommit_example_codecommit_DeleteRepository_section.md)
  + [`GetBranch`](codecommit_example_codecommit_GetBranch_section.md)
  + [`GetRepository`](codecommit_example_codecommit_GetRepository_section.md)
  + [`ListBranches`](codecommit_example_codecommit_ListBranches_section.md)
  + [`ListRepositories`](codecommit_example_codecommit_ListRepositories_section.md)
  + [`UpdateDefaultBranch`](codecommit_example_codecommit_UpdateDefaultBranch_section.md)
  + [`UpdateRepositoryDescription`](codecommit_example_codecommit_UpdateRepositoryDescription_section.md)
  + [`UpdateRepositoryName`](codecommit_example_codecommit_UpdateRepositoryName_section.md)

# CodeCommit 使用 AWS SDKs的動作
<a name="codecommit_code_examples_actions"></a>

下列程式碼範例示範如何使用 AWS SDKs 執行個別 CodeCommit 動作。每個範例均包含 GitHub 的連結，您可以在連結中找到設定和執行程式碼的相關說明。

 下列範例僅包含最常使用的動作。如需完整清單，請參閱《[AWS CodeCommit API 參考](https://docs.aws.amazon.com/codecommit/latest/APIReference/Welcome.html)》。

**Topics**
+ [`BatchGetRepositories`](codecommit_example_codecommit_BatchGetRepositories_section.md)
+ [`CreateBranch`](codecommit_example_codecommit_CreateBranch_section.md)
+ [`CreateRepository`](codecommit_example_codecommit_CreateRepository_section.md)
+ [`DeleteRepository`](codecommit_example_codecommit_DeleteRepository_section.md)
+ [`GetBranch`](codecommit_example_codecommit_GetBranch_section.md)
+ [`GetRepository`](codecommit_example_codecommit_GetRepository_section.md)
+ [`ListBranches`](codecommit_example_codecommit_ListBranches_section.md)
+ [`ListRepositories`](codecommit_example_codecommit_ListRepositories_section.md)
+ [`UpdateDefaultBranch`](codecommit_example_codecommit_UpdateDefaultBranch_section.md)
+ [`UpdateRepositoryDescription`](codecommit_example_codecommit_UpdateRepositoryDescription_section.md)
+ [`UpdateRepositoryName`](codecommit_example_codecommit_UpdateRepositoryName_section.md)

# 搭配使用 `BatchGetRepositories` 與 CLI
<a name="codecommit_example_codecommit_BatchGetRepositories_section"></a>

下列程式碼範例示範如何使用 `BatchGetRepositories`。

------
#### [ CLI ]

**AWS CLI**  
**檢視多個儲存庫的詳細資訊**  
此範例顯示多個 AWS CodeCommit 儲存庫的詳細資訊。  

```
aws codecommit batch-get-repositories \
    --repository-names MyDemoRepo MyOtherDemoRepo
```
輸出：  

```
{
    "repositoriesNotFound": [],
    "repositories": [
         {
            "creationDate": 1429203623.625,
            "defaultBranch": "main",
            "repositoryName": "MyDemoRepo",
            "cloneUrlSsh": "ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo",
            "lastModifiedDate": 1430783812.0869999,
            "repositoryDescription": "My demonstration repository",
            "cloneUrlHttp": "https://codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo",
            "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
            "Arn": "arn:aws:codecommit:us-east-2:111111111111:MyDemoRepo"
            "accountId": "111111111111"
        },
        {
            "creationDate": 1429203623.627,
            "defaultBranch": "main",
            "repositoryName": "MyOtherDemoRepo",
            "cloneUrlSsh": "ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyOtherDemoRepo",
            "lastModifiedDate": 1430783812.0889999,
            "repositoryDescription": "My other demonstration repository",
            "cloneUrlHttp": "https://codecommit.us-east-2.amazonaws.com/v1/repos/MyOtherDemoRepo",
            "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE",
            "Arn": "arn:aws:codecommit:us-east-2:111111111111:MyOtherDemoRepo"
            "accountId": "111111111111"
        }
    ],
    "repositoriesNotFound": []
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [BatchGetRepositories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/batch-get-repositories.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例確認哪些指定的儲存庫可找到和找不到。**  

```
Get-CCRepositoryBatch -RepositoryName MyDemoRepo, MyNewRepo, AMissingRepo
```
**輸出：**  

```
Repositories                            RepositoriesNotFound
------------                            --------------------
{MyDemoRepo, MyNewRepo}                {AMissingRepo}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [BatchGetRepositories](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例確認哪些指定的儲存庫可找到和找不到。**  

```
Get-CCRepositoryBatch -RepositoryName MyDemoRepo, MyNewRepo, AMissingRepo
```
**輸出：**  

```
Repositories                            RepositoriesNotFound
------------                            --------------------
{MyDemoRepo, MyNewRepo}                {AMissingRepo}
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [BatchGetRepositories](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `CreateBranch` 與 CLI
<a name="codecommit_example_codecommit_CreateBranch_section"></a>

下列程式碼範例示範如何使用 `CreateBranch`。

------
#### [ CLI ]

**AWS CLI**  
**建立分支**  
此範例會在 AWS CodeCommit 儲存庫中建立分支。只有在發生錯誤時，此命令才會產生輸出。  
命令：  

```
aws codecommit create-branch --repository-name MyDemoRepo --branch-name MyNewBranch --commit-id 317f8570EXAMPLE
```
輸出：  

```
None.
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-branch.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會建立具有指定儲存庫之指定名稱，以及指定遞交 ID 的新分支。**  

```
New-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch -CommitId 7763222d...561fc9c9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [CreateBranch](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會建立具有指定儲存庫之指定名稱，以及指定遞交 ID 的新分支。**  

```
New-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch -CommitId 7763222d...561fc9c9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateBranch](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `CreateRepository` 與 CLI
<a name="codecommit_example_codecommit_CreateRepository_section"></a>

下列程式碼範例示範如何使用 `CreateRepository`。

------
#### [ CLI ]

**AWS CLI**  
**建立儲存庫**  
此範例會建立儲存庫，並將其與使用者帳戶建立關聯 AWS 。  
命令：  

```
aws codecommit create-repository --repository-name MyDemoRepo --repository-description "My demonstration repository"
```
輸出：  

```
{
    "repositoryMetadata": {
        "repositoryName": "MyDemoRepo",
                "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo",
                "lastModifiedDate": 1444766838.027,
        "repositoryDescription": "My demonstration repository",
                "cloneUrlHttp": "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo",
        "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
                "Arn": "arn:aws:codecommit:us-east-1:111111111111EXAMPLE:MyDemoRepo",
        "accountId": "111111111111"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [CreateRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/create-repository.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會建立具有指定名稱和指定描述的新儲存庫。**  

```
New-CCRepository -RepositoryName MyDemoRepo -RepositoryDescription "This is a repository for demonstration purposes."
```
**輸出：**  

```
AccountId             : 80398EXAMPLE
Arn                   : arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
CloneUrlHttp          : https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CloneUrlSsh           : ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CreationDate          : 9/18/2015 4:13:25 PM
DefaultBranch         :
LastModifiedDate      : 9/18/2015 4:13:25 PM
RepositoryDescription : This is a repository for demonstration purposes.
RepositoryId          : 43ef2443-3372-4b12-9e78-65c27EXAMPLE
RepositoryName        : MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [CreateRepository](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會建立具有指定名稱和指定描述的新儲存庫。**  

```
New-CCRepository -RepositoryName MyDemoRepo -RepositoryDescription "This is a repository for demonstration purposes."
```
**輸出：**  

```
AccountId             : 80398EXAMPLE
Arn                   : arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
CloneUrlHttp          : https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CloneUrlSsh           : ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CreationDate          : 9/18/2015 4:13:25 PM
DefaultBranch         :
LastModifiedDate      : 9/18/2015 4:13:25 PM
RepositoryDescription : This is a repository for demonstration purposes.
RepositoryId          : 43ef2443-3372-4b12-9e78-65c27EXAMPLE
RepositoryName        : MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [CreateRepository](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `DeleteRepository` 與 CLI
<a name="codecommit_example_codecommit_DeleteRepository_section"></a>

下列程式碼範例示範如何使用 `DeleteRepository`。

------
#### [ CLI ]

**AWS CLI**  
**刪除儲存庫**  
此範例示範如何刪除 AWS CodeCommit 儲存庫。  
命令：  

```
aws codecommit delete-repository --repository-name MyDemoRepo
```
輸出：  

```
{
  "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE"
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [DeleteRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/delete-repository.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例強制刪除指定的儲存庫。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除儲存庫，無需提示。**  

```
Remove-CCRepository -RepositoryName MyDemoRepo
```
**輸出：**  

```
43ef2443-3372-4b12-9e78-65c27EXAMPLE
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V4)*》中的 [DeleteRepository](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例強制刪除指定的儲存庫。繼續之前，此命令會先提示確認。新增 -Force 切換變數可刪除儲存庫，無需提示。**  

```
Remove-CCRepository -RepositoryName MyDemoRepo
```
**輸出：**  

```
43ef2443-3372-4b12-9e78-65c27EXAMPLE
```
+  如需 API 詳細資訊，請參閱《*AWS Tools for PowerShell Cmdlet 參考 (V5)*》中的 [DeleteRepository](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `GetBranch` 與 CLI
<a name="codecommit_example_codecommit_GetBranch_section"></a>

下列程式碼範例示範如何使用 `GetBranch`。

------
#### [ CLI ]

**AWS CLI**  
**取得分支的相關資訊**  
此範例會取得 AWS CodeCommit 儲存庫中分支的相關資訊。  
命令：  

```
aws codecommit get-branch --repository-name MyDemoRepo --branch-name MyNewBranch
```
輸出：  

```
{
  "BranchInfo": {
        "commitID": "317f8570EXAMPLE",
                "branchName": "MyNewBranch"
  }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-branch.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會取得指定儲存庫之指定分支的相關資訊。**  

```
Get-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch
```
**輸出：**  

```
BranchName                              CommitId
----------                              --------
MyNewBranch                             7763222d...561fc9c9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [GetBranch](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定儲存庫之指定分支的相關資訊。**  

```
Get-CCBranch -RepositoryName MyDemoRepo -BranchName MyNewBranch
```
**輸出：**  

```
BranchName                              CommitId
----------                              --------
MyNewBranch                             7763222d...561fc9c9
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetBranch](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `GetRepository` 與 CLI
<a name="codecommit_example_codecommit_GetRepository_section"></a>

下列程式碼範例示範如何使用 `GetRepository`。

------
#### [ CLI ]

**AWS CLI**  
**取得儲存庫的相關資訊**  
此範例顯示有關 AWS CodeCommit 儲存庫的詳細資訊。  

```
aws codecommit get-repository \
    --repository-name MyDemoRepo
```
輸出：  

```
{
    "repositoryMetadata": {
        "creationDate": 1429203623.625,
        "defaultBranch": "main",
        "repositoryName": "MyDemoRepo",
        "cloneUrlSsh": "ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/v1/repos/MyDemoRepo",
        "lastModifiedDate": 1430783812.0869999,
        "repositoryDescription": "My demonstration repository",
        "cloneUrlHttp": "https://codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo",
        "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
        "Arn": "arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
        "accountId": "111111111111"
    }
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [GetRepository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/get-repository.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會取得指定儲存庫的資訊。**  

```
Get-CCRepository -RepositoryName MyDemoRepo
```
**輸出：**  

```
AccountId             : 80398EXAMPLE
Arn                   : arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
CloneUrlHttp          : https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CloneUrlSsh           : ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CreationDate          : 9/8/2015 3:21:33 PM
DefaultBranch         :
LastModifiedDate      : 9/8/2015 3:21:33 PM
RepositoryDescription : This is a repository for demonstration purposes.
RepositoryId          : c7d0d2b0-ce40-4303-b4c3-38529EXAMPLE
RepositoryName        : MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [GetRepository](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定儲存庫的資訊。**  

```
Get-CCRepository -RepositoryName MyDemoRepo
```
**輸出：**  

```
AccountId             : 80398EXAMPLE
Arn                   : arn:aws:codecommit:us-east-1:80398EXAMPLE:MyDemoRepo
CloneUrlHttp          : https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CloneUrlSsh           : ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/MyDemoRepo
CreationDate          : 9/8/2015 3:21:33 PM
DefaultBranch         :
LastModifiedDate      : 9/8/2015 3:21:33 PM
RepositoryDescription : This is a repository for demonstration purposes.
RepositoryId          : c7d0d2b0-ce40-4303-b4c3-38529EXAMPLE
RepositoryName        : MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [GetRepository](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `ListBranches` 與 CLI
<a name="codecommit_example_codecommit_ListBranches_section"></a>

下列程式碼範例示範如何使用 `ListBranches`。

------
#### [ CLI ]

**AWS CLI**  
**檢視分支名稱的清單**  
此範例會列出 AWS CodeCommit 儲存庫中的所有分支名稱。  

```
aws codecommit list-branches \
    --repository-name MyDemoRepo
```
輸出：  

```
{
    "branches": [
        "MyNewBranch",
        "main"
    ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListBranches](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-branches.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會取得指定儲存庫的分支名稱清單。**  

```
Get-CCBranchList -RepositoryName MyDemoRepo
```
**輸出：**  

```
master
MyNewBranch
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [ListBranches](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會取得指定儲存庫的分支名稱清單。**  

```
Get-CCBranchList -RepositoryName MyDemoRepo
```
**輸出：**  

```
master
MyNewBranch
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListBranches](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `ListRepositories` 與 CLI
<a name="codecommit_example_codecommit_ListRepositories_section"></a>

下列程式碼範例示範如何使用 `ListRepositories`。

------
#### [ CLI ]

**AWS CLI**  
**檢視儲存庫的清單**  
此範例列出與使用者帳戶相關聯的所有 AWS CodeCommit 儲存庫 AWS 。  
命令：  

```
aws codecommit list-repositories
```
輸出：  

```
{
  "repositories": [
      {
         "repositoryName": "MyDemoRepo"
         "repositoryId": "f7579e13-b83e-4027-aaef-650c0EXAMPLE",
      },
      {
         "repositoryName": "MyOtherDemoRepo"
         "repositoryId": "cfc29ac4-b0cb-44dc-9990-f6f51EXAMPLE"
      }
  ]
}
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [ListRepositories](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/list-repositories.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例依儲存庫名稱，以遞增順序列出所有儲存庫。**  

```
Get-CCRepositoryList -Order Ascending -SortBy RepositoryName
```
**輸出：**  

```
RepositoryId                            RepositoryName
------------                            --------------
c7d0d2b0-ce40-4303-b4c3-38529EXAMPLE    MyDemoRepo
05f30c66-e3e3-4f91-a0cd-1c84aEXAMPLE    MyNewRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [ListRepositories](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例依儲存庫名稱，以遞增順序列出所有儲存庫。**  

```
Get-CCRepositoryList -Order Ascending -SortBy RepositoryName
```
**輸出：**  

```
RepositoryId                            RepositoryName
------------                            --------------
c7d0d2b0-ce40-4303-b4c3-38529EXAMPLE    MyDemoRepo
05f30c66-e3e3-4f91-a0cd-1c84aEXAMPLE    MyNewRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [ListRepositories](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `UpdateDefaultBranch` 與 CLI
<a name="codecommit_example_codecommit_UpdateDefaultBranch_section"></a>

下列程式碼範例示範如何使用 `UpdateDefaultBranch`。

------
#### [ CLI ]

**AWS CLI**  
**變更儲存庫的預設分支**  
此範例會變更 AWS CodeCommit 儲存庫的預設分支。只有在發生錯誤時，此命令才會產生輸出。  
命令：  

```
aws codecommit update-default-branch --repository-name MyDemoRepo --default-branch-name MyNewBranch
```
輸出：  

```
None.
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateDefaultBranch](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-default-branch.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例將指定的儲存庫的預設分支變更為指定的分支。**  

```
Update-CCDefaultBranch -RepositoryName MyDemoRepo -DefaultBranchName MyNewBranch
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [UpdateDefaultBranch](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例將指定的儲存庫的預設分支變更為指定的分支。**  

```
Update-CCDefaultBranch -RepositoryName MyDemoRepo -DefaultBranchName MyNewBranch
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateDefaultBranch](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `UpdateRepositoryDescription` 與 CLI
<a name="codecommit_example_codecommit_UpdateRepositoryDescription_section"></a>

下列程式碼範例示範如何使用 `UpdateRepositoryDescription`。

------
#### [ CLI ]

**AWS CLI**  
**變更儲存庫的描述**  
此範例會變更 AWS CodeCommit 儲存庫的描述。只有在發生錯誤時，此命令才會產生輸出。  
命令：  

```
aws codecommit update-repository-description --repository-name MyDemoRepo --repository-description "This description was changed"
```
輸出：  

```
None.
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateRepositoryDescription](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-repository-description.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會變更指定之儲存庫的描述。**  

```
Update-CCRepositoryDescription -RepositoryName MyDemoRepo -RepositoryDescription "This is an updated description."
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [UpdateRepositoryDescription](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定之儲存庫的描述。**  

```
Update-CCRepositoryDescription -RepositoryName MyDemoRepo -RepositoryDescription "This is an updated description."
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateRepositoryDescription](https://docs.aws.amazon.com/powershell/v5/reference)。

------

# 搭配使用 `UpdateRepositoryName` 與 CLI
<a name="codecommit_example_codecommit_UpdateRepositoryName_section"></a>

下列程式碼範例示範如何使用 `UpdateRepositoryName`。

------
#### [ CLI ]

**AWS CLI**  
**變更儲存庫的名稱**  
此範例會變更 AWS CodeCommit 儲存庫的名稱。只有在發生錯誤時，此命令才會產生輸出。變更 AWS CodeCommit 儲存庫的名稱會變更使用者連線到儲存庫所需的 SSH 和 HTTPS URLs。使用者將無法連接到此儲存庫，直到他們更新連線設定為止。此外，因為儲存庫的 ARN 將會變更，變更儲存庫名稱將使得仰賴於此儲存庫的 ARN 的任何 IAM 使用者政策無效。  
命令：  

```
aws codecommit update-repository-name --old-name MyDemoRepo --new-name MyRenamedDemoRepo
```
輸出：  

```
None.
```
+  如需 API 詳細資訊，請參閱《AWS CLI 命令參考》**中的 [UpdateRepositoryName](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/codecommit/update-repository-name.html)。

------
#### [ PowerShell ]

**Tools for PowerShell V4**  
**範例 1：此範例會變更指定之儲存庫的名稱。**  

```
Update-CCRepositoryName -NewName MyDemoRepo2 -OldName MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V4)》**中的 [UpdateRepositoryName](https://docs.aws.amazon.com/powershell/v4/reference)。

**Tools for PowerShell V5**  
**範例 1：此範例會變更指定之儲存庫的名稱。**  

```
Update-CCRepositoryName -NewName MyDemoRepo2 -OldName MyDemoRepo
```
+  如需 API 詳細資訊，請參閱《AWS Tools for PowerShell Cmdlet 參考 (V5)》**中的 [UpdateRepositoryName](https://docs.aws.amazon.com/powershell/v5/reference)。

------