Skip to content

Instantly share code, notes, and snippets.

@MilesDowe
Created November 22, 2021 18:57
Show Gist options
  • Save MilesDowe/cf427c7b3399175ee6fe1252f9881196 to your computer and use it in GitHub Desktop.
Save MilesDowe/cf427c7b3399175ee6fe1252f9881196 to your computer and use it in GitHub Desktop.
Example of migrating CodeCommit repos from one account to another
  1. 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 and acct_new, respectively.
  1. Add CodeCommit power user permissions to an existing user in AWS console, for both accounts.
  2. 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.
  3. 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}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment