Table of contents
No headings in the article.
We all learned Git when we first started to get into tech. We learned to configure SSH locally and remotely so it becomes easier for us to contribute to Open-source software or our projects. We were used to forking, cloning, committing, and pushing the repository and everything went well.
In case you are not aware of setting up ssh key in your machine, Checkout this article
Now, Let's create a scenario to understand better where this article is going. You get your first job break into tech ๐. Congratulations for staying up til now in the software community and contributing to it commit by commit.
You are told to work on your primary system for the first few weeks. Now, You get to the remote repository copy the clone repository link using SSH, and paste it into your terminal
You get the following error
You see this error considering the fact that you have already setup ssh to one GitHub account and are now trying to clone another GitHub account's repository
The solution to this problem was long and confusing articles. To solve this problem temporarily, I used to work on 2 laptops. One for my contributions and one for my work-related contributions. But, there should be an effective way to do it right. So, Without wasting any time, Let's get into it.
Create a .ssh folder and then create a config file
touch config
While creating the SSH key in your .ssh/ folder, We will be using 2 different names public for a personal account and work for a professional/work account. Copy and paste the below text into your config file
#work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/work
IdentitiesOnly yes
#public account
Host github.com-public
HostName github.com
User git
IdentityFile ~/.ssh/public
IdentitiesOnly yes
Focus on the 2nd line after the comment (below #work account and #public account), That is:
#work account
Host github.com-work
#public account
Host github.com-public
When we clone the repository, The text between them @ and :
is what Host is defined as. We can see from the below image to get a rough idea.
So, When we copy the clone SSH link, We need to make certain changes in the link in the terminal. Let us go through it.
Change the text which lies between @ and :
your clone link to match either the work-related account the public-related account or any account. The text should be the same as the Host we made for each account.
That's it. That's how you can configure multiple GitHub accounts in your one single local machine and make awesome contributions.
I hope you have liked this article. Appreciate your feedback. For informative articles like these, Follow me Shaik Mohammad Abdullah on Twitter and here at hash node.