Multiple GitHub accounts on a machine (Windows)
Most of the developers have more than one GitHub account , say Work and Personal . Using two different systems for each GitHub account is fairly easy to handle but how to manage two accounts on same system ?
I have faced this situation many times, my laziness of not documenting the steps (I also don't have a very good memory :-p) made me spent a decent amount of time in collecting bits and pieces to accomplish the task.
Since you are reading through this , you must be facing the same issue. Let's start solving the problem through below steps :
for the sake of understanding we would assume that your machine already has a GitHub account wired-up named as work. With below steps, we will configure a new account named as personal.
Generate SSH keys for personal account
- run below command in command prompt
ssh-keygen -t rsa -C “your-email-address”
Provide the location where you want to store the newly generated keys
Generating public/private rsa key pair. Enter file in which to save the key (C:\Users\your.username/.ssh/id_rsa):
Make sure not to override id_rsa as this could be your existing key for work account. Provide an identifiable name - similar to this: C:\Users\your.username/.ssh/id_rsa_personal
Optionally provide a passphrase for the newly generated key , enter twice to leave it blank
You should be able to see SSH key files generated at given location. This has two files : -
- id_rsa_personal : This is private key to be stored on your system.
- id_rsa_personal.pub : This is public key which we will configure with GitHub in coming steps.
Add SSH key to GitHub account
- Copy the contents of id_rsa_personal.pub (this file can be opened using and text editor like notepad) and login to your GitHub account.
Navigate to Settings -> SSH and GPG keys , click on New SSH Key button
- Paste the copied content of id_rsa_personal.pub into key field. Optionally provide a unique title to this key.
Update Git Config file
Since a new SSH key has been created and configured on GitHub , now need to specify when we want to use personal account instead of work. For this we need to amend the git config file. This can be edited either using command line or by using any text editor.
Command line : Run the below command in command line
git config core.sshCommand=ssh -i ~/.ssh/id_rsa_personal
Using text editor : Add sshCommand = ssh -i ~/.ssh/id_ra_personal to core list.
Update email and name in Git Config file
You will also need to update the email and name inside Git Config file. This can be done by editing the Git Config file.
Alternatively , command lines can be used to add / update email and name
git config user.name "test" git config user.email email@example.com
Now, you are all set to commit and push the changes to your remote repository
git init git add . git commit -m "First commit" git remote add origin firstname.lastname@example.org:your_username/test.git git push origin master
Hope it helps you !