How to Manage AWS CodeCommit via AWS CLI

Reading Time: 4 minutes

Hello Readers! I hope you all are doing very well. So, In this blog we will see how to manage AWS CodeCommit via AWS CLI. Whatever you are doing with your AWS Management Console You can do it through AWS CLI. 

Now we are going to see how we can create a repository, create a branch and I have got a list of things that I’m going to show you now.

Prerequisites and SetUp:

  1. You must have configured AWS CLI on your system. We can check it through this command.
aws configure
  1. You must have git for performing all the functions and cloning the repo.

So, these are some prerequisites that you must follow before getting started.

Let’s start!

1.List the CodeCommit Repository:

   The command for listing CodeCommit Repository is:

$ aws codecommit list-repositories

You can see here there is no repository found.

2. Create Repository:

$ aws codecommit create-repository --repository-name <name>

You will get output as shown below.

AWS Codecommit
AWS Codecommit

3. Get Details about a Repository:

$ aws codecommit get-repository --repository-name demorepo
Codecommit Repository

4. Cloning Repository:

Move to the AWS Codecommit and copy the link from here for cloning.

AWS Codecommit

I will move inside the repository and will create a file and push this file into the repository.

$ cd demorepo
$ touch myfile
$ git add .
$ git commit -m "added my first file"
$ git push

5. List Branches:

Use the following command for listing the branch of any repository.

$ aws codecommit list-branches --repository-name demorepo
AWS Codecommit

6. Get Details about a particular branch:

$ aws codecommit get-branch --repository-name demorepo --branch-name <branch-name>
AWS Codecommit

Here you will get a commit-id which you can use for further commands.

7. Get Details of the commit to our Repository:

$ aws codecommit get-commit --repository-name demorepo --commit-id <id>

8. Create a Branch:

Use this command for creating the branch in our repository.

$ aws codecommit create-branch --repository-name demorepo --branch-name <branch-name> --commit-id <id>

You can verify it by listing the branches by using this command:

$ aws codecommit list-repositories

So, it’s created as you can see.

9. Update Default Branch

$ aws codecommit update-default-branch --repository-name demorepo --default-branch-name <branch-name>
default branch

You can check it here.


10. Delete a Branch:

$ aws codecommit delete-branch --repository-name demorepo --branch-name <branch-name>

11. Delete CodeCommit Repository:

$ aws codecommit delete-repository --repository-name demorepo

So, Now when you will list the repositories you will find an empty list.

$ aws codecommit list-repositories

Congrats! 👏 We are successfully done now! If you want then you can try more commands by using the help command.


In this blog we have seen how to manage AWS CodeCommit via AWS CLI. We have also seen some commands we can use. Thanks for being with me till the end. If you find this blog helpful do share with your friends.


Written by 

Naincy Kumari is a DevOps Consultant at Knoldus Inc. She is always ready to learn new technologies and tools. She loves painting and dancing.