Manage multiple GitHub accounts and AWS CodeCommit: Short post

github_ssh_config


This post describes how to manage ssh keys for several GitHub accounts and AWS CodeCommit. Even though I'm using AWS CodeCommit, this can be applied to other service providers as well.

Currently, I manage my personal Github, company GitHub, and company AWS CodeCommit. I have three ssh key pairs all together.

Below is the ssh config file (C:\Users\harsha-xcompany\.ssh\config)


How to clone

When cloning we have to use the Host values in the config file. I have replaced the host of the URL with the host value in the config file.

1. Personal account

Original URL: 
git@github.com:h-hub/Java_Practice.git
After replacing host (No need to replace since both host values are the same): 
git clone git@github.com:h-hub/Java_Practice.git

2. Company GitHub account

Original URL: 
git@github.com:xcompany-co/cognito_cloudformation_project.git
After replacing host: 
git clone git@github.xcompany-co:xcompany-co/cognito_cloudformation_project.git

3. AWS CodeCommit account

Original URL: 
ssh://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/xcompany-admin-panel
After replacing host: 
git clone ssh://github-xcompany/v1/repos/xcompany-admin-panel

Once you have cloned properly, you can continue with other git commands.

git config


For personal repositories. I used my Github username and email.
git config --local user.name "h-hub"
git config user.email "harsha.kj89@gmail.com"

For the AWS CodeCommit account, I used my name and company email.
git config --local user.name "harsha Jayamanna"
git config user.email "harsha@akronym.co"

Make sure to cofig before committing any changes because otherwise, your commits won't show your profile properly.

git_commits
git commits



References:

https://www.ssh.com/ssh/config
https://docs.aws.amazon.com/codecommit/latest/userguide/cross-account-user-b.html
https://git-scm.com/docs/git-config



Comments