Migrating AWS CodeCommit to other git repository provider

|

AWS officially announced that they will no longer support AWS CodeCommit effectively since July 25, 2024. Although they mentioned that existing customers will not be affected and continue to use the service as normal. But, this might be the first step and we don’t know the actual direction in the future.

How to Migrate AWS Code Commit Repository to other git repository provider such as GitHub or GitLab?

Pre-requisites on migrating AWS CodeCommit

  1. Make sure that you have the necessary credentials and permissions to both the AWS Management Console and the other provider’s account like GitHub or GitLab.
  2. Clone the repository first before performing the actual migration.
  3. Must have git command in your terminal or shell.

Migrating AWS CodeCommit

  1. First, We have to clone the repository from AWS CodeCommit to your local machine using Git command. If you’re using HTTPS, you can do this by running the following command:

    Note: In my case, my repository url is https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/demo-codecommit-migration
## Syntax

git clone --mirror <remote-git-url>

## Command
git clone --mirror https://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/demo-codecommit-migration

IMPORTANT: don’t forget to specify the --mirror flag. Because if you don’t, the default branch will be the only branch available in your local repo.

2. Next, setup the new repository. e.g GitHub. You can also leave the default settings and disregard creating README.md and .gitignore template.

Add the URL of the created github repository. In my case git@github.com:redopsbay/migrate-codecommit.git:

## Syntax

git remote add <provider> <git-url>


## Actual Command
git remote add github git@github.com:redopsbay/migrate-codecommit.git

3. Migrate the mirrored repository by typing the command:

git push github --mirror

Note

  1. The target remote repository MUST BE EMPTY
  2. Branch protection MUST be temporarily disabled on the target remote repository.

As you can see, all the branches are also pushed to my new repository.

4. Once the push is complete, verify that all files, branches, and tags have been successfully migrated to the new repository provider. You can do this by browsing your repository online or by cloning it to another location and checking it locally.

Automated Migration

GitHub provides a method to automatically import a repository by just providing a git credentials.

Summary

In this post, I described a few methods to migrate your existing AWS codecommit repository to another Git provider such as GitHub. These methods will probably work to other Git provider such as BitBucket or GitLab