AWS CodeCommit is a git repo service. It is generally cheaper than other “pro” options provided by many comapnies. But this document is generally applicable to any git migration. You need to clone the source repo, add a new remote and push the changes.
Steps are given below
SSH Key
First , create a ssh key pair if you have not done so . If you do not have one , use the ssh-keygen command to generate a public and private key. ( For windows users, install git for windows client and then run the commands in the bash terminal that comes with it )
Upload your ssh public key to your user settings area in github or gitlab.
Clone the source Repo
git clone --mirror git@gitlab.com/blah/myproject.git
or
git clone --mirror git@github.com/myproject.git
or any other URL you might have.
This creates a myproject folder in your computer . This is what we are going to push to CodeCommit repo. Remember this is a bare repo just just like a snapshot that is going to AWS code commit repo. It will have all branches and commit history till now. So, make no changes any further in your original git repo.
Prepare AWS account
Account Settings
Login to AWS IAM area, find and click your username under “Users”. Go to “Security Credentials” tab. Find the button called “upload ssh key” and upload your ssh public key in there. After you add it, the screen shows the SSH Key as added and a ID associated with it. Copy the ID . It looks like AKWDCSFF123123SFDF .
Create a ~/.ssh/config file on your machine. Contents should look like below. Match your SSH ID and private key. Now your machine is ready to work with CodeCommit repo.
Host git-codecommit.*.amazonaws.com
User APKAEBLAHEXAMPLE
IdentityFile ~/.ssh/id_rsa
Create a CodeCommit Repo
Go to AWS CodeCommit and Click on Create Repository. Provide a name and click create.
Prepare and push the repo to CodeCommit
Get the repo URL from AWS CodeCommit as given in the below image.
Now run the following commands
cd myproject.git
git remote add aws ssh://git-codecommit.<yourregion>.amazonaws.com/v1/repos/<reponame>
git push --all aws
You should now be able to open the repo in CodeCommit UI in AWS, and see all your branches and commits are there.
Remove the myproject.git folder and do a fresh git clone from the CodeCommit . You can use this repo to do your future work.
If you used Wikis feature in gitlab, then you can use the “checkout” option on the wiki page which is yet another git repo. I recommend creating a seperate repo in AWS CodeCommit and do the same process above to save your Wiki pages as well.