<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=490755098261949&amp;ev=PageView&amp;noscript=1">
Heady Logo White
Heady Logo Purple
Big ideas for small screens.
Don’t miss the future.

Nah, I'm good.

By subscribing you agree to our Privacy Policy.

How to manage multiple Github accounts

Saish Chachad

Author Saish Chachad
Published On Aug 25, 2020
Saish Chachad

Author Saish Chachad
Published On Aug 25, 2020
manage_resp

Introduction

This article is useful for the developer who is dealing with multiple git accounts.

The following steps are the list of command which will help you when dealing with multiple git accounts. Simply copy and paste the commands on your terminal and check the code from your repository.

Step 1

Checking for existing SSH keys

  1. Open Terminal app.
  2. Enter ls -al ~/.ssh to see if existing SSH keys are present: List the files in your .ssh directory, if they exist.
  3. Check the directory listing to see if you already have a public SSH key.
  4. By default, the filenames of public keys are one of the following:

id_dsa.pub
id_ecdsa.pub
id_ed25519.pub
id_rsa.pub

Tip: If you don’t have an existing public and private key pair, or don’t wish to use any of that are available to connect to GitHub, then generate a new SSH key.

 

Step 2

Create new SSH

ssh-keygen -t rsa -b 4096 -C "personalEmail@gmail.com"
ssh-keygen -t rsa -b 4096 -C "workEmail@work.com"
ssh-keygen -t rsa -b 4096 -C "freelanceEmail@work2.com"

 

Step 3

Add your private SSH key to the ssh-agent and store your passphrase in the keychain

ssh-add -K ~/.ssh/id_rsa
ssh-add -K ~/.ssh/id_rsa_work
ssh-add -K ~/.ssh/id_rsa_work2

 

Step 4

See the list of added SSH

ssh-add -l

This will list the fingerprints of all identities.

 

Step 5

Add a new SSH key to your account

$ pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

This will list the fingerprints of all identities.

Tip: If pbcopy isn’t working, you can locate the hidden .ssh folder by opening the file in your favorite text editor and copying it to your clipboard.

  1. Go to your Github account.
  2. In the upper-right corner of any page, click your profile photo, then click Settings

    1_Zz-0nINK5t3TrX0KIz2rYw

  3. In the user settings sidebar, click SSH and GPG keys.

    1_IthaEYgcQlscRMqUhxxOVw

  4. Click New SSH key or Add SSH key.

    1_MdWSb_kdNpbSjDZ_3Bc39A

  5. In the Title field, add a descriptive label for the new key. Paste your key into the Key field.

    1_-gpWpnwo_0Ang-WMgVrY1A

  6. Click Add SSH key.

    1_GffKqrrl8EX8qsH_ERXthA

  7. Follow the same steps to copy id_rsa_work and id_rsa_work2 key onto your work and freelance accounts.

 

Step 6

Make changes in the config file

  1. Go to .ssh folder.
  2. Open config file in any textEditor.
  3. If config file is not present, create one.

cd ~/.ssh
touch config

 

Step 7

Copy and paste this text into the config file

# Personal GitHub account
Host github.com
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa

# Work VSTS account
Host vs-ssh.visualstudio.com-work
HostName vs-ssh.visualstudio.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa_work

# Work2 GitHub account
Host github.com-work2
HostName github.com
User git
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa_work2

In my case, my personal and freelance accounts are on GitHub, and my work account is on VSTS.

 

Step 8

Clone Repo (Freelance Github Account)

Copy the clone URL from Github (from work2 account) and modify as below.

Original url:

git clone git@github.com:(Repo path).git

Modified url:

git clone git@github.com-work2:(Repo path).git

Paste this (modified) URL onto the terminal.

 

Step 9

Configure User attributes

Go into the repository folder from terminal and paste this command.

git config user.name "work2"
git config user.email "freelanceEmail@work2.com"

 

Step 10

Repeat steps 8 and 9 for other (personal and work) accounts

Cheers 🥂


 

Extra Commands for HELP

1.Delete all identities.

ssh-add -D

2. For more help, use the following commands.

ssh -help
ssh-add -help

Group 132 Copy@2x

Interested in a career at Heady?

Excellent! We are always looking for great talent.

app-clips_1
app-clips_2

Interested in a career at Heady?

Excellent! We are always looking for great talent.

LET'S TALK IT OUT.

Figuring out your next step? We're here for you.

Or drop us a line.

hello@heady.io