AWS Codecommit Tutorial – Beginners Guide

AWS codecommit tutorial

In a normal private environment , if you want to host your code using solutions like gitlab, Atlassian stash etc, you will need manage high availability and scalability for your production systems. AWS codecommit is a private managed source control system which is secure, highly scalable and scalable. It is git based and it works the same way like all other git based source control systems like github, stash etc. This allows easy migration of your code repositories to codecomiit and have the same work-flow you used to have. Moreover, codecommit provides out of the box encryption for your source codes which is at rest and in transit. If your applications are hosted in AWS, codecommit would be a good fit for all your source codes.

AWS Codecommit Tutorial

This aws codecommmit tutorial will guide you to get started with AWS codecommit service. To follow this tutorial, you need to have the latest AWS CLI installed on your system. If you do not have the CLI setup follow this link for the setup. It is always advisable to create an IAM user and attach a policy with required access to codecommit.

You Might Like: AWS account security tips

Creating a repository

Like you do in any source control system, the first step is to create a repository for your project. Use the following syntax for creating a repository in codecommit.

 aws codecommit create-repository --repository-name MyProjecRepo --repository-description "Write a description about your project"
[email protected]:~$ aws codecommit create-repository --repository-name myapp --repository-description "This is the code repository for myapp"
    "repositoryMetadata": {
        "repositoryName": "myapp", 
        "cloneUrlSsh": "ssh://", 
        "lastModifiedDate": 1449065689.399, 
        "repositoryDescription": "This is the code repository for myapp", 
        "cloneUrlHttp": "", 
        "creationDate": 1449065689.399, 
        "repositoryId": "2e859c05-06f6-458e-899d-cbc9a589fd33", 
        "Arn": "arn:aws:codecommit:us-east-1:146317666315:myapp", 
        "accountId": "146317666315"
[email protected]:~$ 

Once the command execution is successfull, it returns the output with the codecommit repo url for both ssh and http.

Authentication local git to codecommit

Next step is to configure your local git for authenticating againist codecommmit. So that you will have persmissions to clone, push and do all the remote repository related tasks. You can do that using the credential helper as shown below.

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

Common git config

[email protected]:~/projects$ git config --global "[email protected]"
[email protected]:~/projects$  git config --global "devopscube"

Cloning the Repository

You can clone the remote codecommit repository to your local workstation using the normal git clone command and the repository url you got in the output section when you created the repository.

[email protected]:~/projects$ git clone myrepo
Cloning into 'myrepo'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
[email protected]:~/projects$

performing Common Git Funtions

Now you have an empty repository clonned from codecommit. You can perform all the normal git operations as you perform with any git based source control system as shown below.

Note: If you are using Ubuntu 14.04 as your workstation, you are likely to get a “gnutls_handshake() failed” error. You can rectify this error by following this solution. gnutls_handshake() failed solution

[email protected]:~/projects/myrepo$ touch test.txt
[email protected]:~/projects/myrepo$ git status
On branch master

Initial commit

Untracked files:
  (use "git add ..." to include in what will be committed)


nothing added to commit but untracked files present (use "git add" to track)
[email protected]:~/projects/myrepo$ git add test.txt 
[email protected]:~/projects/myrepo$ git commit -m "first commit"
[master (root-commit) cd12dd2] first commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test.txt
 [email protected]:~/projects/myrepo$ git push -u origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 206 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.
[email protected]:~/projects/myrepo$

Creating a Branch

You can create a branch for your repository using “create-branch” attribute. For this you must pass the commit id to for the new branch to point to.You can get short hash of commit id’s using “git log” command. An example is shown below.

[email protected]:~/projects/myrepo$ git log
commit cd12dd2b35afc3768a2a025654fa01e6ddb54fa4
Author: devopscube <[email protected]>
Date:   Thu Dec 3 18:58:57 2015 +0530

    first commit
[email protected]:~/projects/myrepo$

Once you get the commit id, use the following command to create a new branch. Replace the repository name, branch name and commit id accordingly.

aws codecommit create-branch --repository-name myapp --branch-name newfeature --commit-id cd12dd2b35afc3768a2a025654fa01e6ddb54fa4

List all Branches

You can list all the branches associated with a repository using “list-branches” as shown below.

aws codecommit list-branches --repository-name myapp

Rename a Repository

A repository can be renamed using “update-repository-name” attribute.

aws codecommit update-repository-name --old-name myapp --new-name MyNewApp

Getting Repository Details

To get the information about more than one repository, you can run a batch-get-repositories attribute as shown below.

aws codecommit batch-get-repositories --repository-names myapp railsapp

Deleting a Repository

“delete-repository” attribute is used with the cli to delete a repository.

aws codecommit delete-repository --repository-name MyNewApp


[email protected]:~/projects/myrepo$ aws codecommit delete-repository --repository-name MyNewApp
    "repositoryId": "2e859c05-06f6-458e-899d-cbc9a589fd33"
[email protected]:~/projects/myrepo$

Free DevOps Resources

Get DevOps news, tutorials and resources in your inbox. A perfect way If you want to get started with devops. Like you, we dont like spam.

1 Comment

  1. Mohamed Ali Abidi Reply

    please how can i use this repository into a composer php project !!

Leave a Reply

Your email address will not be published. Required fields are marked *