- Add AWS creds (access + secret keys) for both the "original" and "new" account locations to your credentials file
- In this example, we save them as profiles
acct_orig
andacct_new
, respectively.
- Add CodeCommit power user permissions to an existing user in AWS console, for both accounts.
- For each of the users you added CodeCommit permissions to, also generate a Git username & password for that user in AWS IAM console. Keep it somewhere safe.
- On the machine you've saved the AWS credentials to, perform the following script
# for each repo in the acct_orig account/region
repo="<your repo name>"
aws codecommit create-repository --repository-name "${repo}" --profile acct_new
# for each repo
git clone "https://git-codecommit.<region>.amazonaws.com/v1/repos/${repo}"
# provide acct_orig user's Git credentials
cd ${repo}
git remote add new_acct "https://git-codecommit.<region>.amazonaws.com/v1/repos/${repo}"
# for each branch, run:
git push --set-upstream new_acct <branch>
# provide acct_new user's Git credentials
cd .. && rm -rf ${repo}