Sometimes work requires you to use multiple GitHub accounts. For example, you might have a personal account and a client account. Whatever the reason, you might need to use multiple GitHub accounts on your Mac.
Agency life requires you to work with multiple clients, each of them having their own GitHub internal policies and requirements. Probably most will just give you access during the development phase, but others will insist on creating a new GitHub account for you. This is a good practice, but it can be a bit annoying to have to switch between accounts all the time. Here’s how to add multiple GitHub accounts to your Mac.
Step 1: Create a new SSH key for each of your GitHub accounts
The first thing you need to do is to create a new SSH key for each of your GitHub accounts. You can do this by following the instructions on GitHub’s website, or simply by running the following command in your terminal:
--apple-use-keychain is a flag that tells the ssh-agent to use the macOS Keychain to store the SSH key.
Step 3. Add the SSH key to your GitHub account
Now that you have created the SSH key and added it to the ssh-agent, you need to add it to your GitHub account. You can do this by following the instructions on GitHub’s website -- should always be up to date, but at high level follow these simple steps:
Copy the SSH key to your clipboard with the following command: pbcopy < ~/.ssh/client-a-github-username.pub
One thing to note is that you need to use the github.com<-client-a> even though they're both hosted on GitHub. This is because the SSH config file tells the SSH client to use the IdentityFile for github.com-client-a, and the host is an alias for github.com defined in the HostName field.
Your main agency account is set up by default, so you don't need to specify anything after github.com in the host when cloning your agency's or personal repositories.