

# Getting started
<a name="getting-started-topnode"></a>

The easiest way to get started with CodeCommit is to follow the steps in [Getting started with CodeCommit ](getting-started-cc.md). If you are new to Git and CodeCommit, you should also consider following the steps in [Getting started with Git and CodeCommit](getting-started.md). This helps you familiarize yourself with CodeCommit and the basics of using Git when interacting with your CodeCommit repositories.

You can also follow the tutorial in [Simple Pipeline Walkthrough with CodePipeline and CodeCommit](https://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-cc.html) to learn how to use your CodeCommit repository as part of a continuous delivery pipeline.

The tutorials in this section are written with the assumption that you have completed the [prerequisites and setup](setting-up.md), including:
+ Assigning permissions to the IAM user.
+ Setting up credential management for HTTPS or SSH connections on the local machine you are using for this tutorial.
+ Configuring the AWS CLI if you want to use the command line or terminal for all operations, including creating the repository.

**Topics**
+ [Getting started with AWS CodeCommit](getting-started-cc.md)
+ [Getting started with Git and AWS CodeCommit](getting-started.md)

# Getting started with AWS CodeCommit
<a name="getting-started-cc"></a>

This tutorial shows you how to use some key CodeCommit features. First, you create a repository and commit some changes to it. Then, you browse the files and view the changes. You can also create a pull request so other users can review and comment on changes to your code. 

If you want to migrate existing code to CodeCommit, see [Migrate to AWS CodeCommit](how-to-migrate-repository.md).

If you are unfamiliar with Git, consider completing [Getting started with Git and CodeCommit](getting-started.md) too. After you complete these tutorials, you should have enough practice to start using CodeCommit for your own projects and in team environments.

The CodeCommit console includes helpful information in a collapsible panel that you can open from the information icon (![\[The information icon that opens and closes the help panel on a page.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-info-icon.png)) or any **Info** link on the page. You can close this panel at any time.

![\[Viewing additional guidance in the console\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-guidance-open.png)


The CodeCommit console also provides a way to quickly search for your resources, such as repositories, build projects, deployment applications, and pipelines. Choose **Go to resource** or press the `/` key, and then type the name of the resource. Any matches appear in the list. Searches are case insensitive. You only see resources that you have permissions to view. For more information, see [Viewing resources in the console](auth-and-access-control-iam-identity-based-access-control.md#console-resources). 

## Prerequisites
<a name="getting-started-cc-prereqs"></a>

Before you begin, you must complete the [prerequisites and setup](setting-up.md) procedure, including:
+ Assigning permissions to the IAM user.
+ Setting up credential management for HTTPS or SSH connections on the local machine you use for this tutorial.
+ Configuring the AWS CLI if you want to use the command line or terminal for all operations, including to create the repository.

**Topics**
+ [Prerequisites](#getting-started-cc-prereqs)
+ [Step 1: Create a CodeCommit repository](#getting-started-cc-create-repo)
+ [Step 2: Add files to your repository](#getting-started-cc-add)
+ [Step 3: Browse the contents of your repository](#getting-started-cc-browse)
+ [Step 4: Create and collaborate on a pull request](#getting-started-cc-pullrequest)
+ [Step 5: Clean up](#getting-started-cc-clean-up)
+ [Step 6: Next steps](#getting-started-cc-next)

## Step 1: Create a CodeCommit repository
<a name="getting-started-cc-create-repo"></a>

You can use the CodeCommit console to create a CodeCommit repository. If you already have a repository you want to use for this tutorial, you can skip this step. 

**Note**  
Depending on your usage, you might be charged for creating or accessing a repository. For more information, see [Pricing](http://aws.amazon.com/codecommit/pricing) on the CodeCommit product information page.

**To create the CodeCommit repository**

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. Use the region selector to choose the AWS Region where you want to create the repository. For more information, see [Regions and Git connection endpoints](regions.md).

1. On the **Repositories** page, choose **Create repository**. 

1. On the **Create repository** page, in **Repository name**, enter a name for your repository (for example, **MyDemoRepo**).
**Note**  
Repository names are case sensitive and can be no longer than 100 characters. For more information, see [Limits](limits.md#limits-repository-names).

1. (Optional) In **Description**, enter a description (for example, **My demonstration repository**). This can help you and other users identify the purpose of the repository.

1. (Optional) Choose **Add tag** to add one or more repository tags (a custom attribute label that helps you organize and manage your AWS resources) to your repository. For more information, see [Tagging repositories in AWS CodeCommit](how-to-tag-repository.md).

1. (Optional) Expand **Additional configuration** to specify whether to use the default AWS managed key or your own customer managed key for encrypting and decrypting the data in this repository. If you choose to use your own customer managed key, you must ensure that it is available in the AWS Region where you are creating the repository, and that the key is active. For more information, see [AWS Key Management Service and encryption for AWS CodeCommit repositories](encryption.md).

1. (Optional) Select **Enable Amazon CodeGuru Reviewer for Java and Python** if this repository will contain Java or Python code, and you want to have CodeGuru Reviewer analyze that code. CodeGuru Reviewer uses multiple machine learning models to find code defects and to automatically suggest improvements and fixes in pull requests. For more information, see the Amazon CodeGuru Reviewer User Guide.

1. Choose **Create**. 

![\[Creating a repository from the console\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-create-repository.png)


**Note**  
If you use a name other than `MyDemoRepo` for your repository, be sure to use it in the remaining steps.

When the repository opens, you see information about how to add files directly from the CodeCommit console. 

## Step 2: Add files to your repository
<a name="getting-started-cc-add"></a>

You can add files to your repository by:
+ Creating a file in the CodeCommit console. If you create the first file for a repository in the console, a branch is created for you named *main*. This branch is the default branch for your repository.
+ Uploading a file from your local computer using the CodeCommit console. If you upload the first file for a repository from the console, a branch is created for you named *main*. This branch is the default branch for your repository.
+ Using a Git client to clone the repository to your local computer, and then adding, committing, and pushing files to the CodeCommit repository. A branch is created for you as part of that first commit from Git, and it is set as the default branch for your repository. The name of the branch is the default choice of your Git client. Consider configuring your Git client to use *main* as the name for the initial branch.

**Note**  
You can create branches and change the default branch for a repository at any time. For more information, see [Working with branches in AWS CodeCommit repositories](branches.md).

The simplest way to get started is to open the CodeCommit console and add a file. By doing so, you also create a default branch for your repository named *main*. For instructions about how to add a file and create a first commit to a repository using the AWS CLI, see [Create the first commit for a repository using the AWS CLI](how-to-create-commit.md#create-first-commit).

**To add a file to the repository**

1. In the navigation bar for the repository, choose **Code**.

1. Choose **Add file**, and then choose whether to create a file or upload a file from your computer. This tutorial shows you how to do both.

1. To add a file, do the following:

   1. In the drop-down list of branches, choose the branch where you want to add the file. The default branch is selected automatically for you. In the example shown here, the default branch is named *main*. If you want to add the file to a different branch, choose a different branch. 

   1.  In **File name**, enter a name for the file. In the code editor, enter the code for the file. 

   1. In **Author name**, enter the name you want displayed to other repository users. 

   1. In **Email address**, enter an email address. 

   1. (Optional) In **Commit message**, enter a brief message. Although this is optional, we recommend that you add a commit message to help your team members understand why you added this file. If you do not enter a commit message, a default message is used.

   1. Choose **Commit changes**.

   To upload a file, do the following: 
   + If you're uploading a file, choose the file you want to upload.   
![\[A view of uploading a file in the CodeCommit console\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commit-first-file.png)
   + In **Author name**, enter the name you want displayed to other repository users. 
   + In **Email address**, enter an email address.
   + (Optional) In **Commit message**, enter a brief message. Although this is optional, we recommend that you add a commit message to help your team members understand why you added this file. If you do not enter a commit message, a default message is used.
   + Choose **Commit changes**.

For more information, see [Working with files in AWS CodeCommit repositories](files.md).

To use a Git client to clone the repository, install Git on your local computer, and then clone the CodeCommit repository. Add some files to the local repo and push them to the CodeCommit repository. For an in-depth introduction, try the [Getting started with Git and CodeCommit](getting-started.md). If you are familiar with Git, but are not sure how to do this with a CodeCommit repository, you can view examples and instructions in [Create a commit](how-to-create-commit.md), [Step 2: Create a local repo](getting-started.md#getting-started-set-up-folders), or [Connect to a repository](how-to-connect.md). 

After you have added some files to the CodeCommit repository, you can view them in the console.

## Step 3: Browse the contents of your repository
<a name="getting-started-cc-browse"></a>

You can use the CodeCommit console to review the files in a repository or quickly read the contents of a file. This helps you determine which branch to check out or whether to create a local copy of a repository. 

**To browse the repository**

1. From **Repositories**, choose MyDemoRepo.

1. The page displays the contents in the default branch of your repository. To view another branch or to view the code at a specific tag, choose the branch or tag you want to view from the list. In the following screenshot, the view is set to the **main** branch.  
![\[Browse the contents of a repository\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-code-browse.png)

1. To view the contents of a file in your repository, choose the file from the list. To change the color of the displayed code, choose the settings icon.  
![\[View the contents of a file\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-code-browse-file.png)

   For more information, see [Browse files in a repository](how-to-browse.md).

1. To browse the commit history of the repository, choose **Commits**. The console displays the commit history for the default branch, in reverse chronological order. Review the commit details by author, date, and more.  
![\[The commit history view in the console\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-code-history.png)

1. To view the commit history by [branch](branches.md) or by [Git tag](how-to-view-tag-details.md), choose the branch or tag you want to view from the list. 

1. To view the differences between a commit and its parent commit, choose the abbreviated commit ID. You can choose how the changes are displayed, including showing or hiding white space changes, and whether to view changes inline (**Unified** view) or side by side (**Split** view). 
**Note**  
Your preferences for viewing code and other console settings are saved as browser cookies whenever you change them. For more information, see [Working with user preferences](user-preferences.md).  
![\[Changes shown in Unified view, with white space changes visible\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commit-changes2c.png)

1. To view all comments on a commit, choose the commit and then scroll through the changes to view them inline. You can also add your own comments and reply to the comments made by others. 

   For more information, see [Comment on a commit](how-to-commit-comment.md). 

1. To view the differences between any two commits specifiers, including tags, branches, and commit IDs, in the navigation pane, choose **Commits**, and then choose **Compare commits**.   
![\[Comparing a commit to the tip of a branch in Split view\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-compare-4.png)

   For more information, see [Browse the commit history of a repository](how-to-view-commit-details.md#how-to-view-commit-details-console-history) and [Compare commits](how-to-compare-commits.md). 

1. In **Commits**, choose the **Commit visualizer** tab.   
![\[A graphical view of a repository in the console\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-cv-complex1.png)

   The commit graph is displayed, with the subject line for each commit shown next to its point in the graph. The subject line display is limited to 80 characters.

1. To see more details about a commit, choose its abbreviated commit ID. To render the graph from a specific commit, choose that point in the graph. For more information, see [View a graph of the commit history of a repository](how-to-view-commit-details.md#how-to-view-commit-details-console-visualizer).

## Step 4: Create and collaborate on a pull request
<a name="getting-started-cc-pullrequest"></a>

When you work in a repository with other users, you can collaborate on code and review changes. You can create a pull request so that other users can review and comment on your code changes in a branch. You can also create one or more approval rules for the pull request. For example, you can create an approval rule that requires at least two other users to approve the pull request before it can be merged. After the pull request is approved, you can merge those changes into its destination branch. If you set up notifications for your repository, repository users can receive emails about repository events (for example, for pull requests or when someone comments on code). For more information, see [Configuring notifications for events in an AWS CodeCommit repository](how-to-repository-email.md).

**Important**  
Before you can create a pull request, you must create a branch that contains the code changes you want to review. For more information, see [Create a branch](how-to-create-branch.md).

**To create and collaborate on a pull request**

1. In the navigation pane, choose **Pull requests**.

1. In **Pull request**, choose **Create pull request**. 
**Tip**  
You can also create pull requests from **Branches** and **Code**.

   In **Create pull request**, in **Source**, choose the branch that contains the changes you want reviewed. In **Destination**, choose the branch where you want the reviewed code to be merged when the pull request is closed. Choose **Compare**. 

1. Review the merge details and changes to confirm that the pull request contains the changes and commits you want reviewed. If so, in **Title**, enter a title for this review. This is the title that appears in the list of pull requests for the repository. In **Description**, enter details about what this review is about and any other useful information for reviewers. Choose **Create**.  
![\[Creating a pull request\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-create.png)

1. Your pull request appears in the list of pull requests for the repository. You can filter the view to show only open requests, closed requests, requests that you created, and more.   
![\[Viewing pull requests in a repository\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-view.png)

1. You can add an approval rule to your pull request to ensure that certain conditions are met before it can be merged. To add an approval rule to your pull request, choose the pull request from the list. On the **Approvals** tab, choose **Create approval rule**. 

1. In **Rule name**, give the rule a descriptive name. For example, if you want to require two people to approve a pull request before it can be merged, you might name the rule **Require two approvals before merge**. In **Number of approvals needed**, enter **2**, the number you want. The default is 1. Choose **Submit**. To learn more about approval rules and approval pool members, see [Create an approval rule for a pull request](how-to-create-pull-request-approval-rule.md).  
![\[Creating an approval rule for a pull request\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-create-approval-rule.png)

1. If you configured notifications for your repository and chose to notify users of pull request events, users receive email about your new pull request. Users can view the changes and comment on specific lines of code, files, and the pull request itself. They can also reply to comments with text and emojis. If necessary, you can push changes to the pull request branch, which updates the pull request.  
![\[Adding an emoji reaction to a comment on a pull request.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-commenting-commenttab.png)

1. If you are satisfied about the changes made in the request, choose **Approve**. You can choose to approve a pull request even if no approval rules are configured for that pull request. This provides a clear record of your having reviewed the pull request and your approval of the changes. You can also choose to revoke your approval if you change your mind.   
![\[Viewing approvals on a pull request\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-pull-request-approvals.png)
**Note**  
You cannot approve a pull request if you created it.

1. When you are satisfied that all the code changes have been reviewed and agreed to, from the pull request, do one of the following:
   + If you want to close the pull request without merging branches, choose **Close pull request**.
   + If you want to merge the branches and close the pull request, choose **Merge**. You can choose between the merge strategies available for your code, which depend on the differences between the source and destination branches, and whether to automatically delete the source branch after the merge is complete. After you have made your choices, choose **Merge pull request** to complete the merge.  
![\[A pull request showing the merge strategies available for the merge in the CodeCommit console.\]](http://docs.aws.amazon.com/codecommit/latest/userguide/images/codecommit-merge-squash.png)
   + If there are merge conflicts in the branches that cannot be resolved automatically, you can resolve them in the CodeCommit console, or you can use your local Git client to merge the branches and then push the merge. For more information, see [Resolve conflicts in a pull request in an AWS CodeCommit repository](how-to-resolve-conflict-pull-request.md).
**Note**  
You can always manually merge branches, including pull request branches, by using the **git merge** command in your local repo and pushing your changes. 

For more information, see [Working with pull requests](pull-requests.md) and [Working with approval rule templates](approval-rule-templates.md).

## Step 5: Clean up
<a name="getting-started-cc-clean-up"></a>

If you no longer need the CodeCommit repository, you should delete the CodeCommit repository and other resources you used in this exercise so you won't continue to be charged for the storage space. 

**Important**  
This action cannot be undone. After you delete this repository, you can no longer clone it to any local repo or shared repo. You also can no longer pull data from or push data to it, or perform any Git operations, from any local repo or shared repo.   
If you configured notifications for your repository, deleting the repository also deletes the Amazon CloudWatch Events rule created for the repository. It does not delete the Amazon SNS topic used as a target for that rule.  
If you configured triggers for your repository, deleting the repository does not delete the Amazon SNS topics or Lambda functions you configured as the targets of those triggers. Be sure to delete those resources if you don't need them. For more information, see [Delete triggers from a repository](how-to-notify-delete.md).

**To delete the CodeCommit repository**

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In **Repositories**, choose the repository you want to delete. If you followed the naming convention in this topic, it is named **MyDemoRepo**. 

1. In the navigation pane, choose **Settings**. 

1. On the **Settings** page, in **Delete repository**, choose **Delete repository**.

1. Type **delete**, and then choose **Delete**. The repository is permanently deleted. 

## Step 6: Next steps
<a name="getting-started-cc-next"></a>

Now that you have familiarized yourself with CodeCommit and some of its features, consider doing the following:
+ If you are new to Git and CodeCommit or want to review examples of using Git with CodeCommit, continue to the [Getting started with Git and CodeCommit](getting-started.md) tutorial.
+ If you want to work with others in a CodeCommit repository, see [Share a repository](how-to-share-repository.md). (If you want to share your repository with users in another Amazon Web Services account, see [Configure cross-account access to an AWS CodeCommit repository using roles](cross-account.md).)
+ If you want to migrate a repository to CodeCommit, follow the steps in [Migrate to CodeCommit](how-to-migrate-repository.md).
+ If you want to add your repository to a continuous delivery pipeline, follow the steps in [Simple Pipeline Walkthrough](https://docs.aws.amazon.com/codepipeline/latest/userguide/getting-started-cc.html).
+ If you want to learn more about products and services that integrate with CodeCommit, including examples from the community, see [Product and service integrations](integrations.md).

# Getting started with Git and AWS CodeCommit
<a name="getting-started"></a>

If you are new to Git and CodeCommit, this tutorial helps you learn some simple commands to get you started. If you are already familiar with Git, you can skip this tutorial and go to [Getting started with CodeCommit ](getting-started-cc.md).

In this tutorial, you create a repository that represents a local copy of the CodeCommit repository, which we refer to as a local repo. 

After you create the local repo, you make some changes to it. Then you send (push) your changes to the CodeCommit repository.

You also simulate a team environment where two users independently commit changes to their local repo and push those changes to the CodeCommit repository. The users then pull the changes from the CodeCommit repository to their own local repo to see the changes the other user made.

You also create branches and tags and manage some access permissions in the CodeCommit repository. 

After you complete this tutorial, you should have enough practice with the core Git and CodeCommit concepts to use them for your own projects. 

Complete the [prerequisites and setup](setting-up.md), including:
+ Assign permissions to the IAM user.
+ Set up CodeCommit to connect to a repository using [HTTPS](setting-up-gc.md), SSH, or [**git-remote-codecommit**](setting-up-git-remote-codecommit.md). For more information about these choices, see [Setting up for AWS CodeCommit](setting-up.md).
+ Configure the AWS CLI if you want to use the command line or terminal for all operations, including creating the repository.

**Topics**
+ [Step 1: Create a CodeCommit repository](#getting-started-create-repo)
+ [Step 2: Create a local repo](#getting-started-set-up-folders)
+ [Step 3: Create your first commit](#getting-started-create-commit)
+ [Step 4: Push your first commit](#getting-started-init-repo)
+ [Step 5: Share the CodeCommit repository and push and pull another commit](#getting-started-pull-commits)
+ [Step 6: Create and share a branch](#getting-started-branching)
+ [Step 7: Create and share a tag](#getting-started-tags)
+ [Step 8: Set up access permissions](#getting-started-permissions)
+ [Step 9: Clean up](#getting-started-clean-up)

## Step 1: Create a CodeCommit repository
<a name="getting-started-create-repo"></a>

In this step, you use the CodeCommit console to create the repository. 

You can skip this step if you already have a CodeCommit repository you want to use. 

**Note**  
Depending on your usage, you might be charged for creating or accessing a repository. For more information, see [Pricing](http://aws.amazon.com/codecommit/pricing) on the CodeCommit product information page.

**To create the CodeCommit repository**

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. Use the region selector to choose the AWS Region where you want to create the repository. For more information, see [Regions and Git connection endpoints](regions.md).

1. On the **Repositories** page, choose **Create repository**. 

1. On the **Create repository** page, in **Repository name**, enter a name for your repository (for example, **MyDemoRepo**).
**Note**  
Repository names are case sensitive and can be no longer than 100 characters. For more information, see [Limits](limits.md#limits-repository-names).

1. (Optional) In **Description**, enter a description (for example, **My demonstration repository**). This can help you and other users identify the purpose of the repository.

1. (Optional) Choose **Add tag** to add one or more repository tags (a custom attribute label that helps you organize and manage your AWS resources) to your repository. For more information, see [Tagging repositories in AWS CodeCommit](how-to-tag-repository.md).

1. (Optional) Expand **Additional configuration** to specify whether to use the default AWS managed key or your own customer managed key for encrypting and decrypting the data in this repository. If you choose to use your own customer managed key, you must ensure that it is available in the AWS Region where you are creating the repository, and that the key is active. For more information, see [AWS Key Management Service and encryption for AWS CodeCommit repositories](encryption.md).

1. (Optional) Select **Enable Amazon CodeGuru Reviewer for Java and Python** if this repository will contain Java or Python code, and you want to have CodeGuru Reviewer analyze that code. CodeGuru Reviewer uses multiple machine learning models to find code defects and to automatically suggest improvements and fixes in pull requests. For more information, see the Amazon CodeGuru Reviewer User Guide.

1. Choose **Create**. 

**Note**  
The remaining steps in this tutorial use `MyDemoRepo` for the name of the CodeCommit repository. If you choose a different name, be sure to use it throughout this tutorial.

For more information about creating repositories, including how to create a repository from the terminal or command line, see [Create a repository](how-to-create-repository.md).

## Step 2: Create a local repo
<a name="getting-started-set-up-folders"></a>

In this step, you set up a local repo on your local machine to connect to your repository. To do this, you select a directory on your local machine that represents the local repo. You use Git to clone and initialize a copy of your empty CodeCommit repository inside of that directory. Then you specify the Git user name and email address used to annotate your commits. 

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. In the region selector, choose the AWS Region where the repository was created. Repositories are specific to an AWS Region. For more information, see [Regions and Git connection endpoints](regions.md).

1. Find the repository you want to connect to from the list and choose it. Choose **Clone URL**, and then choose the protocol you want to use when cloning or connecting to the repository. This copies the clone URL.
   + Copy the HTTPS URL if you are using either Git credentials with your IAM user or the credential helper included with the AWS CLI.
   + Copy the HTTPS (GRC) URL if you are using the **git-remote-codecommit** command on your local computer.
   + Copy the SSH URL if you are using an SSH public/private key pair with your IAM user.
**Note**  
 If you see a **Welcome** page instead of a list of repositories, there are no repositories associated with your AWS account in the AWS Region where you are signed in. To create a repository, see [Create an AWS CodeCommit repository](how-to-create-repository.md) or follow the steps in the [Getting started with Git and CodeCommit](#getting-started) tutorial.

1. (Optional) We recommend that you configure your local Git client to use **main** as the name for the default branch for your repository. This is the name used for the default branch in all examples in this guide. It is also the same default branch name CodeCommit uses if you make your first commit in the console. Run the following command to configure the default branch name globally for your system:

   ```
   git config --global init.defaultBranch main
   ```

   If you prefer to use a different default branch name for all your repositories, replace **main** with your preferred name. This tutorial assumes that your default branch is named *main*.

   If you want to use different default branch names for different repositories, you can set this attribute locally (**--local**) instead of globally (**--global**).

1. At the terminal or command prompt, clone the repository with the **git clone** command and provide the clone URL you copied in step 3. Your clone URL depends on which protocol and configuration you use. For example, if you are using HTTPS with Git credentials to clone a repository named *MyDemoRepo* in the US East (Ohio) Region:

   ```
   git clone https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo my-demo-repo
   ```

   If you are using HTTPS with **git-remote-codecommit**:

   ```
   git clone codecommit://MyDemoRepo my-demo-repo
   ```

   If you are using SSH:

   ```
   git clone ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo my-demo-repo
   ```
**Note**  
If you see an error when attempting to clone a repository, you might not have completed the setup necessary for your local computer. For more information, see [Setting up for AWS CodeCommit](setting-up.md).

## Step 3: Create your first commit
<a name="getting-started-create-commit"></a>

In this step, you create your first commit in your local repo. To do this, you create two example files in your local repo. You use Git to stage the change to, and then commit the change to, your local repo.

1. Use a text editor to create the following two example text files in your directory. Name the files `cat.txt` and `dog.txt`:

   ```
   cat.txt
   -------
   The domestic cat (Felis catus or Felis silvestris catus) is a small, usually furry, domesticated, and carnivorous mammal.
   ```

   

   ```
   dog.txt
   -------
   The domestic dog (Canis lupus familiaris) is a canid that is known as man's best friend.
   ```

1. Run **git config** to add your user name and email address represented by placeholders *your-user-name* and *your-email-address* to your local repo. This makes it easier to identify the commits you make: 

   ```
   git config --local user.name "your-user-name"
   git config --local user.email your-email-address
   ```

1. If you did not set your default branch name globally when you created the local repo, run the following command to set the default branch name to **main**:

   ```
   git config --local init.defaultBranch main
   ```

1. Run **git add** to stage the change:

   ```
   git add cat.txt dog.txt
   ```

1. Run **git commit** to commit the change:

   ```
   git commit -m "Added cat.txt and dog.txt"
   ```
**Tip**  
To see details about the commit you just made, run **git log**.

## Step 4: Push your first commit
<a name="getting-started-init-repo"></a>

In this step, you push the commit from your local repo to your CodeCommit repository. 

Run **git push** to push your commit through the default remote name Git uses for your CodeCommit repository (`origin`), from the default branch in your local repo (`main`):

```
git push -u origin main
```

**Tip**  
After you have pushed files to your CodeCommit repository, you can use the CodeCommit console to view the contents. For more information, see [Browse files in a repository](how-to-browse.md).

## Step 5: Share the CodeCommit repository and push and pull another commit
<a name="getting-started-pull-commits"></a>

In this step, you share information about the CodeCommit repository with a fellow team member. The team member uses this information to get a local copy, make some changes to it, and then push the modified local copy to your CodeCommit repository. You then pull the changes from the CodeCommit repository to your local repo. 

In this tutorial, you simulate the fellow user by having Git create a directory separate from the one you created in [step 2](#getting-started-set-up-folders). (Typically, this directory is on a different machine.) This new directory is a copy of your CodeCommit repository. Any changes you make to the existing directory or this new directory are made independently. The only way to identify changes to these directories is to pull from the CodeCommit repository. 

Even though they're on the same local machine, we call the existing directory your *local repo* and the new directory the *shared repo*.

From the new directory, you get a separate copy of the CodeCommit repository. You then add a new example file, commit the changes to the shared repo, and then push the commit from the shared repo to your CodeCommit repository.

Lastly, you pull the changes from your repository to your local repo and then browse it to see the changes committed by the other user.

1. Switch to the `/tmp` directory or the `c:\temp` directory.

1. Run **git clone** to pull down a copy of the repository into the shared repo:

   For HTTPS:

   ```
   git clone https://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo shared-demo-repo
   ```

   For HTTPS with **git-remote-codecommit**:

   ```
   git clone codecommit://MyDemoRepo shared-demo-repo
   ```

   For SSH:

   ```
   git clone ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo shared-demo-repo
   ```
**Note**  
When you clone a repository using SSH on Windows operating systems, you might need to add the SSH key ID to the connection string as follows:  

   ```
   git clone ssh://Your-SSH-Key-ID@git-codecommit.us-east-2.amazonaws.com/v1/repos/MyDemoRepo my-demo-repo
   ```
For more information, see [For SSH connections on Windows](setting-up-ssh-windows.md).

   In this command, `MyDemoRepo` is the name of your CodeCommit repository. `shared-demo-repo` is the name of the directory Git creates in the `/tmp` directory or the `c:\temp` directory. After Git creates the directory, Git pulls down a copy of your repository into the `shared-demo-repo` directory.

1. Switch to the `shared-demo-repo` directory:

   ```
   (For Linux, macOS, or Unix) cd /tmp/shared-demo-repo
   (For Windows) cd c:\temp\shared-demo-repo
   ```

1. Run **git config** to add another user name and email address represented by placeholders *other-user-name* and *other-email-address*. This makes it easier to identify the commits the other user makes: 

   ```
   git config --local user.name "other-user-name"
   git config --local user.email other-email-address
   ```

1. Use a text editor to create the following example text file in the `shared-demo-repo` directory. Name the file `horse.txt`:

   ```
   horse.txt
   -------
   The horse (Equus ferus caballus) is one of two extant subspecies of Equus ferus.
   ```

1. Run **git add** to stage the change to the shared repo:

   ```
   git add horse.txt
   ```

1. Run **git commit** to commit the change to the shared repo:

   ```
   git commit -m "Added horse.txt"
   ```

1. Run **git push** to push your initial commit through the default remote name Git uses for your CodeCommit repository (`origin`), from the default branch in your local repo (`main`):

   ```
   git push -u origin main
   ```

1. Switch to your local repo and run **git pull** to pull into your local repo the commit the shared repo made to the CodeCommit repository. Then run **git log** to see the commit that was initiated from the shared repo.

## Step 6: Create and share a branch
<a name="getting-started-branching"></a>

In this step, you create a branch in your local repo, make a few changes, and then push the branch to your CodeCommit repository. You then pull the branch to the shared repo from your CodeCommit repository. 

A branch allows you to independently develop a different version of the repository's contents (for example, to work on a new software feature without affecting the work of your team members). When that feature is stable, you merge the branch into a more stable branch of the software.

You use Git to create the branch and then point it to the first commit you made. You use Git to push the branch to the CodeCommit repository. You then switch to your shared repo and use Git to pull the new branch into your shared local repo and explore the branch.

1. From your local repo, run **git checkout**, specifying the name of the branch (for example, `MyNewBranch`) and the ID of the first commit you made in the local repo. 

   If you don't know the commit ID, run **git log** to get it. Make sure the commit has your user name and email address, not the user name and email address of the other user. This is to simulate that `main` is a stable version of the CodeCommit repository and the `MyNewBranch` branch is for some new, relatively unstable feature:

    

   ```
   git checkout -b MyNewBranch commit-ID
   ```

1. Run **git push** to send the new branch from the local repo to the CodeCommit repository:

   ```
   git push origin MyNewBranch
   ```

1. Now, pull the branch into the shared repo and check your results:

   1. Switch to the shared repo directory (shared-demo-repo).

   1. Pull in the new branch (**git fetch origin**).

   1. Confirm that the branch has been pulled in (**git branch --all** displays a list of all branches for the repository).

   1. Switch to the new branch (**git checkout MyNewBranch**).

   1. Confirm that you have switched to the `MyNewBranch` branch by running **git status** or **git branch**. The output shows which branch you are on. In this case, it should be `MyNewBranch`. 

   1. View the list of commits in the branch (**git log**).

   Here's the list of Git commands to call:

   ```
   git fetch origin
   git branch --all
   git checkout MyNewBranch
   git branch or git status
   git log
   ```

1. Switch back to the `main` branch and view its list of commits. The Git commands should look like this:

    

   ```
   git checkout main
   git log
   ```

1. Switch to the `main` branch in your local repo. You can run **git status** or **git branch**. The output shows which branch you are on. In this case, it should be `main`. The Git commands should look like this:

    

   ```
   git checkout main
   git branch or git status
   ```

## Step 7: Create and share a tag
<a name="getting-started-tags"></a>

In this step, you create two tags in your local repo, associate the tags with commits, and then push the tags to your CodeCommit repository. You then pull the changes from the CodeCommit repository to the shared repo. 

A tag is used to give a human-readable name to a commit (or branch or even another tag). You would do this, for example, if you want to tag a commit as `v2.1`. A commit, branch, or tag can have any number of tags associated with it, but an individual tag can be associated with only one commit, branch, or tag. In this tutorial, you tag one commit as `release` and one as `beta`.

You use Git to create the tags, pointing the `release` tag to the first commit you made and the `beta` tag to the commit made by the other user. You then use Git to push the tags to the CodeCommit repository. Then you switch to your shared repo and use Git to pull the tags into your shared local repo and explore the tags.

1. From your local repo, run **git tag**, specifying the name of the new tag (`release`) and the ID of the first commit you made in the local repo. 

   If you don't know the commit ID, run **git log** to get it. Make sure the commit has your user name and email address, not the user name and email address of the other user. This is to simulate that your commit is a stable version of the CodeCommit repository:

   ```
   git tag release commit-ID
   ```

   Run **git tag** again to tag the commit from the other user with the `beta` tag. This is to simulate that the commit is for some new, relatively unstable feature:

    

   ```
   git tag beta commit-ID
   ```

1. Run **git push --tags** to send the tags to the CodeCommit repository.

1. Now pull the tags into the shared repo and check your results:

   1. Switch to the shared repo directory (shared-demo-repo).

   1. Pull in the new tags (**git fetch origin**).

   1. Confirm that the tags have been pulled in (**git tag** displays a list of tags for the repository).

   1. View information about each tag (**git log release** and **git log beta**).

   Here's the list of Git commands to call:

   ```
   git fetch origin
   git tag
   git log release
   git log beta
   ```

1. Try this out in the local repo, too:

   ```
   git log release
   git log beta
   ```

## Step 8: Set up access permissions
<a name="getting-started-permissions"></a>

In this step, you give a user permission to synchronize the shared repo with the CodeCommit repository. This is an optional step. It's recommended for users who are interested in learning about how to control access to CodeCommit repositories when users use Git credentials or SSH key pairs are used with IAM users for access to CodeCommit repositories. 

**Note**  
If you are using federated access, temporary credentials, or a web identity provider such as IAM Identity Center, set up users, access, and permissions for your identity provider, and then use **git-remote-codecommit**. For more information, see [Setup steps for HTTPS connections to AWS CodeCommit with git-remote-codecommit](setting-up-git-remote-codecommit.md) and [Connecting to AWS CodeCommit repositories with rotating credentials](temporary-access.md).

To do this, you use the IAM console to create a user, who, by default, does not have permissions to synchronize the shared repo with the CodeCommit repository. You can run **git pull** to verify this. If the new user doesn't have permission to synchronize, the command doesn't work. Then you go back to the IAM console and apply a policy that allows the user to use **git pull**. Again, you can run **git pull** to verify this. 

This step is written with the assumption you have permissions to create IAM users in your Amazon Web Services account. If you don't have these permissions, you can't perform the procedures in this step. Skip ahead to [Step 9: Clean up](#getting-started-clean-up) to clean up the resources you used for your tutorial.

1. Sign in to the AWS Management Console and open the IAM console at [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/).

   Be sure to sign in with the same user name and password you used in [Setting up ](setting-up.md).

1. In the navigation pane, choose **Users**, and then choose **Create New Users**.

1. In the first **Enter User Names** box, enter an example user name (for example, **JaneDoe-CodeCommit**). Select the **Generate an access key for each user** box, and then choose **Create**.

1. Choose **Show User Security Credentials**. Make a note of the access key ID and secret access key or choose **Download Credentials**. 

1. Follow the instructions in [For HTTPS users using Git credentials](setting-up-gc.md) to generate and supply the credentials of the IAM user.

   If you want to use SSH, follow the instructions in [SSH and Linux, macOS, or Unix: Set up the public and private keys for Git and CodeCommit](setting-up-ssh-unixes.md#setting-up-ssh-unixes-keys-unixes) or [Step 3:  Set up the public and private keys for Git and CodeCommit ](setting-up-ssh-windows.md#setting-up-ssh-windows-keys-windows) to set up the user with public and private keys.

1. Run **git pull**. The following error should appear:

   For HTTPS:

    `fatal: unable to access 'https://git-codecommit.us-east-2.amazonaws.com/v1/repos/repository-name/': The requested URL returned error: 403`. 

   For SSH:

   `fatal: unable to access 'ssh://git-codecommit.us-east-2.amazonaws.com/v1/repos/repository-name/': The requested URL returned error: 403`. 

   The error appears because the new user doesn't have permission to synchronize the shared repo with the CodeCommit repository.

1. Return to the IAM console. In the navigation pane, choose **Policies**, and then choose **Create Policy**. (If a **Get Started** button appears, choose it, and then choose **Create Policy**.)

1. Next to **Create Your Own Policy**, choose **Select**.

1. In the **Policy Name** box, enter a name (for example, **CodeCommitAccess-GettingStarted**).

1. In the **Policy Document** box, enter the following, which allows an IAM user to pull from any repository associated with the IAM user:

    

------
#### [ JSON ]

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "codecommit:GitPull"
         ],
         "Resource": "*"
       }
     ]
   }
   ```

------

    
**Tip**  
If you want the IAM user to be able to push commits to any repository associated with the IAM user, enter this instead:  

****  

   ```
   {
     "Version":"2012-10-17",		 	 	 
     "Statement": [
       {
         "Effect": "Allow",
         "Action": [
           "codecommit:GitPull",
           "codecommit:GitPush"
         ],
         "Resource": "*"
       }
     ]
   }
   ```
For information about other CodeCommit action and resource permissions you can give to users, see [Authentication and access control for AWS CodeCommit](auth-and-access-control.md).

1. In the navigation pane, choose **Users**.

1. Choose the example user name (for example, **JaneDoe-CodeCommit**) to which you want to attach the policy.

1. Choose the **Permissions** tab.

1. In **Managed Policies**, choose **Attach Policy**.

1. Select the **CodeCommitAccess-GettingStarted** policy you just created, and then choose **Attach Policy**.

1. Run **git pull**. This time the command should work and an `Already up-to-date` message should appear. 

1. If you are using HTTPS, switch to your original Git credentials or, if using **git-remote-codecommit**, your usual profile. For more information, see the instructions in [Setup for HTTPS users using Git credentials](setting-up-gc.md) or [Setup steps for HTTPS connections to AWS CodeCommit with git-remote-codecommit](setting-up-git-remote-codecommit.md).

   If you are using SSH, switch to your original keys. For more information, see [SSH and Linux, macOS, or Unix: Set up the public and private keys for Git and CodeCommit](setting-up-ssh-unixes.md#setting-up-ssh-unixes-keys-unixes) or [Step 3:  Set up the public and private keys for Git and CodeCommit ](setting-up-ssh-windows.md#setting-up-ssh-windows-keys-windows).

You've reached the end of this tutorial. 

## Step 9: Clean up
<a name="getting-started-clean-up"></a>

In this step, you delete the CodeCommit repository you used in this tutorial, so you won't continue to be charged for the storage space. 

You also remove the local repo and shared repo on your local machine because they won't be needed after you delete the CodeCommit repository.

**Important**  
After you delete this repository, you won't be able to clone it to any local repo or shared repo. You also won't be able to pull data from it, or push data to it, from any local repo or shared repo. This action cannot be undone.

### To delete the CodeCommit repository (console)
<a name="getting-started-clean-up-console"></a>

1. Open the CodeCommit console at [https://console.aws.amazon.com/codesuite/codecommit/home](https://console.aws.amazon.com/codesuite/codecommit/home).

1. On the **Dashboard** page, in the list of repositories, choose **MyDemoRepo**. 

1. In the navigation pane, choose **Settings**. 

1. On the **Settings** page, in **Delete repository**, choose **Delete repository**.

1. In the box next to **Type the name of the repository to confirm deletion**, enter **MyDemoRepo**, and then choose **Delete**. 

### To delete the CodeCommit repository (AWS CLI)
<a name="getting-started-clean-up-cli"></a>

Run the [delete-repository](how-to-delete-repository.md#how-to-delete-repository-cli) command:

```
aws codecommit delete-repository --repository-name MyDemoRepo
```

### To delete the local repo and shared repo
<a name="getting-started-delete-repos"></a>

For Linux, macOS, or Unix: 

```
cd /tmp
rm -rf /tmp/my-demo-repo
rm -rf /tmp/shared-demo-repo
```

For Windows: 

```
cd c:\temp
rd /s /q c:\temp\my-demo-repo
rd /s /q c:\temp\shared-demo-repo
```