Cover Image

How to manage multiple Git accounts on one computer using SSH config

Problem Statement

Why will i have multiple Git accounts?

Ideal Solution

Generate SSH Key pairs

$ ssh-keygen -t rsa -b 4096 -C "personalemail@email.com"
Adding SSh key to Github account
Adding personal SSH key to Github
$ ssh-keygen -t rsa -b 4096 -C "workemail@email.com"

Use SSH config file to manage multiple Git accounts

touch ~/.ssh/config
Host personal
HostName github.com
User gitUsername
IdentityFile ~/.ssh/id_rsa

Host work
HostName github.com
User gitUsername
IdentityFile ~/.ssh/id_rsa_work
$ git clone personal:username/repository.git
$ git clone work:username/repository.git
$ git remote set-url origin personal:username/repository.git
$ git pull origin branchName // pull latest from  branchName
$ git push origin branchName //push to branchName

--

--

Software Engineer [https://uchaudhary.com.np]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store