I have two Github accounts: oanhnn (personal) and superman (for work). I want to use both accounts on same computer (without typing password everytime, when doing git push or pull).
Use ssh keys and define host aliases in ssh config file (each alias for an account).
Edit/Create ssh config file (
1 2 3 4 5 6 7 8 9 10 11 # Default github account: oanhnn Host github.com HostName github.com IdentityFile ~/.ssh/oanhnn_private_key IdentitiesOnly yes # Other github account: superman Host github-superman HostName github.com IdentityFile ~/.ssh/superman_private_key IdentitiesOnly yes
1 2 $ ssh-add ~/.ssh/oanhnn_private_key $ ssh-add ~/.ssh/superman_private_key
Test your connection
1 2 $ ssh -T email@example.com $ ssh -T git@github-superman
With each command, you may see this kind of warning, type
1 2 3 The authenticity of host 'github.com (22.214.171.124)' can't be established. RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx: Are you sure you want to continue connecting (yes/no)?
If everything is OK, you will see these messages:
1 Hi oanhnn! You've successfully authenticated, but GitHub does not provide shell access.
1 Hi superman! You've successfully authenticated, but GitHub does not provide shell access.
Now all are set, just clone your repositories
1 2 3 4 $ git clone git@github-superman:org2/project2.git /path/to/project2 $ cd /path/to/project2 $ git config user.email "firstname.lastname@example.org" $ git config user.name "Super Man"