Using Git With Multiple GitHub Accounts
Last updated Dec 10, 2022
Using git with multiple GitHub accounts present many problems for the user because one simply cannot use the same SSH public key for different accounts.
You can use HTTP but then you have to input your GitHub username and password everytime you have to push/pull.
We have created the guide below so you can use GitHub using multiple accounts with the easiest setup.
The steps to use GitHub using multiple accounts:
Create your new GitHub user
Here at Narra Labs, we follow a naming pattern for naming a new GitHub user. If your personal GitHub username for example is
westoque, and you are working for a company named
narralabs, then your new company GitHub account username would be
Generate a new ssh key pair for your new user using
ssh-keygenand follow the instructions. Make sure to name the SSH key using the same pattern as your newly created GitHub username.
westoque@milan$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/westoque/.ssh/id_rsa): westoque-narralabs Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in westoque-narralabs Your public key has been saved in westoque-narralabs.pub The key fingerprint is: SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX email@example.com The key's randomart image is: +---[RSA 3072]----+ | X XXXXXX | | X X XXXX | | X XXXX | | X X XX | | X XXX | | X X X | | X | | | | | +----[SHA256]-----+
Two files will be generated by the command above:
- The private key:
- The public key:
- The private key:
- Move the new SSH key files to your
mv westoque-narralabs westoque-narralabs.pub ~/.ssh
Modify your SSH config by modifying
Add the line below to tell the SSH program that you have a new host using the following configurations.
Host github-westoque-narralabs User git HostName github.com IdentityFile ~/.ssh/id_rsa_westoque_narralabs
Clone the project using your new host:
The original GitHub SSH clone link would look like below:
You then have to modify it using your new host:
Then clone the project:
git clone github-westoque-narralabs:brackets.git
- You can now push/pull like normal for this specific repository.
You can repeat the steps above for another GitHub account.