AWS CodeCommit – Setup git on Linux with multiple AWS Acccount origins for AWS CodeCommit repository/s
Sometimes it is useful to work on and update duplicate code repositories across multiple AWS Accounts, particular if one of the accounts is owned by a different organization and thus cross-account AWS CodePipeline deployment is not an option.
HowTo
- Repeat the following IAM setup in the target AWS accounts.
- Create an AWS IAM group with the appropriate IAM policy giving access to the AWS CodeCommit repositories. Then create a user-specific service user as a member of that group, it should be enabled for programmatic access not console access. Generate a public key [ssh-keygen -t rsa <filename>] and assign it to the
- Navigate to the .ssh folder on your local machine.
- Create a file named config.
- Paste the following in the config file and change the values accordingly
- Navigate to the clone of the repository on your local machine through the command line.
- Type git remote -v → lists all the currently configured remote repositories.
- Type git remote set-url <name_of_remote_repository_server> ssh://<hostname>/<version>/repos/<repository_name>
- Check if the changes are reflected by typing git remote -v
- The URLs must be set for all of the remote repositories.
- Test if it works by typing git fetch <name_of_remote_repository_server> <branch_name>
February 29, 2021