In this guide , We will learn to migrate a git repository to AWS CodeCommit.

codecommit

What is AWS CodeCommit?

  • CodeCommit is a secure, highly scalable, managed source control service that hosts private Git repositories.
  • CodeCommit eliminates the need for us to manage our own source control system or worry about scaling its infrastructure.
  • We can use CodeCommit to store anything from code to binaries. It supports the standard functionality of Git, so it works seamlessly with your existing Git-based tools.

Features of CodeCommit

Store the code securely – Repositories can be encrypted at rest as well as in transit.

Fully managed service by AWS – CodeCommit removes the burden of administration. As It provides Highly available and durable service.

Work collaboratively on the code – Developers can work on the same code and then can review each other’s code , Before merging with the branches.It also supports pull requests and commenting on the code changes.

Store anything , anytime – There is no limit in the file type and the size of the repository.

Easily integrate with AWS and 3rd party services – CodeCommit can be integrated with other AWS services , By doing so , It increases the speed and frequency of the development cycle.

Easy to scale version control projects – It can handle repositories with large number of files , branches , file sizes and lengthy revision history.

Easy to migrate files – Any Git-based repositories can be migrated easily to the AWS CodeCommit.

Steps Involved

  • Creating AWS CodeCommit Repository
  • Setup HTTPS Git Credentials for AWS CodeCommit Authentication
  • Cloning Remote Git Repository to Local system
  • Pushing Local Git repository to AWS CodeCommit

Prerequisites

Make sure the IAM user have access to Create repository in the AWS CodeCommit.

Step 1 : Creating AWS CodeCommit Repository

Login to AWS Codecommit Console.Make sure you choose the preferred region.

Click Create repository

codecommit

Provide a name for the repository and add a description for the repository.

codecommit

You can optionally add tags to the repository.

If the repository is for Java code, Then we can enable Amazon CodeGuru Reviewer using which we can improve the quality of the code for all the pull requests in the repository.

codecommit

Enabling this option , Will automatically create an IAM role ggranting permission for the CodeGuru to review the repositories in the AWS CodeCommit.

And Click Create

After the repository is created , You can click Repositories in the Navigation pane , To list all the repositories.

codecommit

And then click the Repository , Using HTTPS / SSH connection , We can connect with the AWS CodeCommit Repository.

We can clone the Repository using the Copy Link.

Step 2 : HTTPS Git Credentials for AWS CodeCommit

For the IAM users to be able to access and authenticate with the AWS CodeCommit repository , We need to either setup SSH or HTTPS based authentication for each IAM users.

Login to IAM Console.In the naviagtion pane , Choose Users

Click the IAM user , and then Choose Security Credentials

Under HTTPS Git credentials for AWS CodeCommit , Click Generate Credentials , You will get username and Password , Make a note of it.

We will need these credentials while pushing Local Git repository to AWS CodeCommit Repository.

Step 3 : Cloning Git Repository to Local System

In this step , We will create a clone of the existing remote Git repository to the local system , Which is called local git repository.

In the below command , We use –mirror to clone a bare copy of the remote git repository and the repository will be clone to a directory named awscommit-repo.

The bare repo is used only for migration.

git clone --mirror https://github.com/Rahultest005/test-demo.git awscommit-repo

After the remote repo is cloned to the folder in the local machine.We can then push the local repo to the AWS CodeCommit repository.

To learn more about Git Command , Click here

Step 4 : Pushing Local Git repository to AWS CodeCommit

Change to the folder where you have cloned the remote Git repository.

cd awscommit-repo

We will use git push command with –all option to push all the branches of the repository.

Here we will be using HTTPS authentication to push the local repo to AWS CodeCommit repository.

The below command , Will only pushes branches of the repository , But it will not push tags.

git push https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/test-codecommit-repo --all
codecommit

If you want to push tags of the repository as well , The run the below command.

We have replaced –all option with –tags

git push https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/test-codecommit-repo --tags
codecommit

We have successfully migrated the Remote Git repository to AWS CodeCommit.

Now You can delete the local repo and create a clone of the repository from the AWS CodeCommit and start working on it.

Step 5 : Verifying AWS CodeCommit Repository

Lets verify whether all the contents of the remote Git repository along with the Branches and Tags are present.

Login to AWS CodeCommit console , In the navigation pane , Choose Repositories.You can find the lists of repo’s here.

codecommit

Click the Repository , And you can find the details such as Branch , Tag , Copy URL etc.

codecommit

You can chose between tags and branches and verify the contents of the repository.

codecommit

After You have verified , You can start working on the repository.

Conclusion

We have successfully migrated Remote Git repository to AWS CodeCommit Repository.

Thanks for reading , Hope you found it helpful.

Please do check out my other articles.