Mastering Multiple GitHub Accounts: A Step-by-Step Guide for Your Local Machine

Mastering Multiple GitHub Accounts: A Step-by-Step Guide for Your Local Machine

An e2e guide on setting up two or more GitHub accounts in your system

Recently I felt the need of setting up my work github account on my personal laptop. On a simple Google search I found few guides but none of them were smooth enough while following and also do not cover all my requirements.

So here I thought of sharing my git workflow for my personal and work related projects. Here on I’ll be illustrating setup for two accounts : personal and work.

Setup SSH key for both accounts


There are multiple ways two connect your machine to your GitHub account hosted on GitHub server, such as GitHub CLI, SSH and deprecated http login.

If you have just one single account in your machine I’ll suggest you to use github CLI, it’s easy, fast and beginner friendly.

But for multiple accounts using SSH setup is the best way. So let’s start :

Create SSH keys

Let’s first generate SSH key for your personal account.

While running below command the terminal will ask for a paraphrase, you may leave it blank and hit enter. Also the email id and username need not to be exactly same as your actual credentials. The -C flag is a comment and -f flag is the file name where your key will be stored.

     $ cd ~/.ssh
     $ ssh-keygen -t rsa -C "" -f "keshav_git"

Now repeat the same step for your work account.

  $ cd ~/.ssh
  $ ssh-keygen -t rsa -C "" -f "keshav_work_git"

Add SSH keys to SSH agent

Your machine has a SSH agent to keep track of all SSH keys and use them while making SSH connections.

First you will need to start your ssh-agent :

eval `ssh-agent -s`

Now add ssh keys to your ssh agent.

ssh-add ~/.ssh/keshav_git
ssh-add ~/.ssh/keshav_work_git

Add SSH keys to your GitHub Accounts

Inside the ~/.ssh directory you will find two public keys file with the name as and keshav_work_git in my case. You can open these files in any of text editor of your choice such as Vim, nano, kwrite , notepad etc.

Let’s first open the file, it’s my ssh key for personal account. Copy the content of this file and paste it on your personal GitHub account as instructed below.

  • Goto Settings > SSH and GPG keys > New SSH Key

  • Paste your copied public key and give any easily identifiable name such as my_windows_machine etc.

Repeat the above steps for you work account as well.

Creating a config file

Create a file with the name config inside your ~/.ssh directory. Edit as per your naming convention and copy the below content inside config file.

     #keshav-personal account
          User git
          IdentityFile ~/.ssh/keshav_git

     #keshav-work account
          User git
          IdentityFile ~/.ssh/keshav_work_git

Using new setup for using GitHub

With this setup you can clone and make changes in your personal and work related repositories. For example I want to clone my private repository which has the SSH url as

To clone this repo I need to run below command in my terminal. Note that I’ve modified to -keshav-personal this will ensure that my shell automatically fetch ssh key from ~/.ssh/config file with hostname as which is my personal GitHub configuration.

git clone

Make sure you push commits with correct author name

While working with multiple git accounts you don’t want to make a commit in your work repository with your personal git username. To avoid this just set the repository specific username in the cloned directory.

So for instance if I am working on my personal repository I’ll make sure to set below username and email in my cloned repository so it will override the globally setup username. GitHub identifies contributor’s GitHub profile using their emails so it’s the most that you set correct email in your repository.

git config "" && git config "alpha951"

Add correct remote origin to your cloned repository

To push or pull to the correct account we need to add the remote origin to the project. So for the example we discussed before I’ll use below command to setup correct remote origin.

 git remote add origin

To update remote origin for existing repository you can use below command

git remote set-url origin

Now you can simply use git pull and git push commands to update your local projects and commit contributions to the remote.

Voila! You have successfully set up your GitHub accounts. I hope this helped.