@@ -0,0 +1,3238 @@
+// snippet-comment:%5BThese are tags for the AWS doc team's sample catalog. Do not remove.%5D%0A// snippet-sourcedescription:%5BCreateBranch.java demonstrates how to create a branch.%5D%0A// snippet-service:%5BAWS CodeCommit%5D%0A// snippet-keyword:%5BJava%5D%0A// snippet-keyword:%5BAWS CodeCommit%5D%0A// snippet-keyword:%5BCode Sample%5D%0A// snippet-sourcetype:%5Bfull-example%5D%0A// snippet-sourcedate:%5B2020-09-30%5D%0A// snippet-sourceauthor:%5BAWS - scmacdon%5D%0A%0A/**%0A * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.%0A *%0A * This file is licensed under the Apache License, Version 2.0 (the %22License%22).%0A * You may not use this file except in compliance with the License. A copy of%0A * the License is located at%0A *%0A * http://aws.amazon.com/apache2.0/%0A *%0A * This file is distributed on an %22AS IS%22 BASIS, WITHOUT WARRANTIES OR%0A * CONDITIONS OF ANY KIND, either express or implied. See the License for the%0A * specific language governing permissions and limitations under the License.%0A *%0A */%0Apackage com.example.commit;%0A%0A// snippet-start:%5Bcodecommit.java2.create_branch.import%5D%0Aimport software.amazon.awssdk.regions.Region;%0Aimport software.amazon.awssdk.services.codecommit.CodeCommitClient;%0Aimport software.amazon.awssdk.services.codecommit.model.CodeCommitException;%0Aimport software.amazon.awssdk.services.codecommit.model.CreateBranchRequest;%0A// snippet-end:%5Bcodecommit.java2.create_branch.import%5D%0A%0Apublic class CreateBranch %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A%0A        final String USAGE = %22%5Cn%22 +%0A                %22Usage:%5Cn%22 +%0A                %22    CreateBranch %3CrepoName%3E %3CbranchName%3E %3CcommitId%3E %5Cn%5Cn%22 +%0A                %22Where:%5Cn%22 +%0A                %22    repoName - the name of the repository,%5Cn%22 +%0A                %22    branchName -  the name of the branch,%5Cn%22 +%0A                %22    commitId  - The ID of the commit to point the new branch to %5Cn%22;%0A%0A          if (args.length %3C 3) %7B%0A              System.out.println(USAGE);%0A              System.exit(1);%0A          %7D%0A%0A        /* Read the name from command args*/%0A        String repoName = args%5B0%5D;%0A        String branchName = args%5B1%5D;%0A        String commitId = args%5B2%5D;%0A%0A        Region region = Region.US_EAST_1;%0A        CodeCommitClient codeCommitClient = CodeCommitClient.builder()%0A                .region(region)%0A                .build();%0A%0A        createSpecificBranch(codeCommitClient, repoName, branchName, commitId);%0A    %7D%0A%0A    // snippet-start:%5Bcodecommit.java2.create_branch.main%5D%0A    public static void createSpecificBranch(CodeCommitClient codeCommitClient,%0A                                            String repoName,%0A                                            String branchName,%0A                                            String commitId) %7B%0A%0A      try %7B%0A        CreateBranchRequest branchRequest = CreateBranchRequest.builder()%0A                .branchName(branchName)%0A                .repositoryName(repoName)%0A                .commitId(commitId)%0A                .build();%0A%0A            codeCommitClient.createBranch(branchRequest);%0A            System.out.println(%22Branch %22+branchName + %22 was created%22);%0A%0A      %7D catch (CodeCommitException e) %7B%0A            System.err.println(e.getMessage());%0A            System.exit(1);%0A      %7D%0A    %7D%0A    // snippet-end:%5Bcodecommit.java2.create_branch.main%5D%0A%7D%0A

Create CreateBranch.java