After joining my first job they gave me a new mac mini, previously I used to work on my laptop but mac mini feels more convenient now. As you all know new company means you will get your new working email id. then you might need to use it create a new github account. (github is just for an example, this process valid for any git remote provider)
Then the real struggle starts. How to manage personal and work github accounts in the same machine.
Generate 2 ssh keys, means you have to have two public keys and two private keys in your .ssh folder
ex:- id_rsa_work id_rsa_personal id_rsa_work.pub id_rsa_personal.pub
ssh-keygen -t rsa
copy public ssh keys, work ssh goes to work github and personal ssh goes to personal github. so now you have added your public keys respectively.
pbcopy < ~/.ssh/id_rsa_work.pub pbcopy < ~/.ssh/id_rsa_personal.pub
Now we have to create another file in .ssh folder called config and paste the code below
# Personal GitHub Host personal HostName github.com User git AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa_personal # Work GitHub Host work HostName github.com User git AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa_work Host * IdentitiesOnly yes
Suppose you want to clone a repo from your working github account.
git clone email@example.com:work-account/project.git
you have to replace
work. so it will look follows. actully
work is the name you gave in the config file.
git clone work:work-account/project.git
git remote add origin firstname.lastname@example.org:work-account/project.git
git remote add origin work:work-account/project.git
I hope this will make your life easier and happy version controlling.