Consider scenario, where you have two Git accounts on your machine, and want to manage different Github accounts. I assume that you have installed GIt, and created Gihub accounts. You can check my short post about using git with Visual Studio Code: Git things with VSCode.
These are steps which I take in order to accomplish this:
Set up SSH Keys
$ cd ~/.ssh
$ ssh-keygen -t rsa -C "firstname.lastname@example.org"
# save it as id_rsa_1
$ ssh-keygen -t rsa -C "email@example.com"
# save it as id_rsa_2
Add the keys to your Github accounts
Go to “Account Settings”/ “SSH Keys”/ “Add SSH key”
Create a configuration file to manage the separate keys
Create a ‘config’ file in ~/.ssh/:
# Default GitHub
# 2nd GitHub
Update stored identities
To automatically load them every time when Bash starts you can edit ‘.bash_profile’ file:
eval $(ssh-agent -s)
Taking action in Git using second account:
git clone firstname.lastname@example.org:UserName/repo.git
First you have to define user, for convenience on local level:
git config --local user.name "UserName"
git config --local user.email "email@example.com"
Things to remember:
- Github recognises users by e-mail.
- Each level of Git config (system, global, local) overrides values of the previous one.