How to use multiple GitHub accounts on the same computer

Luis Barral
Luis Barral
July 25, 2022
GitHub
Tutorial
How to use multiple GitHub accounts on the same computer

Looking to use multiple GitHub accounts on the same computer?

Look no further: In this post we will provide a step-by-step tutorial on how to do just that.

Let's get started!

SSH Key for every account

1 - First, you need to make sure you have an SSH key for every account. You can follow the steps from this official GitHub tutorial to achieve this: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account

2 - Store the keys of every account in your ~/.ssh directory:

Store account keys in ssh directory

3 - Ensure the files have the right permissions. You don't want to have insecure keys :)

Issue the following command for each private key:

A gitconfig file to rule them all

1 - Next, you will need to add a general gitconfig file:

2 - We will add these lines to the .gitconfig file to use our mainAccount globally, and our secondaryAccount only in the specificFolder. Of course, you can add as many GitHub accounts and folders as you like:

A gitconfig file for every account

1 - Create a git config file for the main account:

2 - Add these lines to the file:

3 - Create a git config file for the secondary account:

4 - Add these lines to the file:

Add SSH keys to your computer

So, the SSH Agent can take care of the authentication for you, and you don’t have to type in passwords at the terminal. We want to run these lines every time we start a terminal, so we will add them to the startup file.

1 - First, remove old keys:

2 - If you're on a Mac, add these to your ~/.zshrc (if you are using zsh) or to your ~/.bashrc (if you are using bash):

Or, if you're using Linux, add:

3 - To check if the ssh keys were added, you can list them:

And that’s all!

You can go now to your specificFolder and run:

It will show the name you set up in your secondary account.

Also, you can go to any other folder of your system, run the same command and it will show you the name you set up in your main account.

We hope you've found this article useful. Thanks for reading!

Don't miss a thing, subscribe to our monthly Newsletter!

Thanks for subscribing!
Oops! Something went wrong while submitting the form.

Behind the scenes of Ethereum Pet Shop tutorial

As a follow-up to our serverless REST API post, this article provides a thorough step-by-step guide on how to creating a GraphQL API boilerplate based on Hasura and the AWS stack.

March 30, 2020
Read more ->
Blockchain
Tutorial

Best way to debug React Native apps

Learn about the different methods for debugging React Native apps and why we advise using the React Native Debugger as the most efficient tool for this task.

December 17, 2019
Read more ->
React Native
Tutorial

Contact

Ready to get started?
Use the form or give us a call to meet our team and discuss your project and business goals.
We can’t wait to meet you!

Write to us!
info@vairix.com

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.