How to use two git on the same Linux/Mac?

Ankit Kumar
2 min readSep 24, 2021

I am assuming you have a company/organization Github account and a personal GitHub account and now you want to use both on your PC.

The steps are pretty simple and without wasting time let’s do it together.

Step 1. Create a new SSH Key. Open a terminal and enter

ssh-keygen -t rsa -C "your-email-address"

Make sure ~/.ssh/id_rsa doesn’t replace your existing ssh key, you can change the name of the new or the old one.

Step 2. Connect your key to Github

Login to your GitHub account and Setting -> SSH and GPG keys in the left panel. Add the new ssh key here.

Where can you get your ssh key?

Enter vim ~/.ssh/id_rsa in your terminal and you will get your entire key. Copy the entire string and paste it into GitHub page -> ssh -> Key ( Begins with ssh-rsa) ….

Step 3. Set your configuration

Create a config file in your .ssh directory and add

#Default GitHub 
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
Host github-Personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_2

Save the page and exit.

Test:

git init
echo ‘README added’ > README.md
git add README.md
git remote add origin git@github-Personal:Personal/test
git push origin master

Note: We changed our host from git@github.com to git@github-Personal.

See, that was quick and easy steps, Thanks and Have a nice day. 😃

--

--