Dual GitHub Domination
Your Laptop's Guide to Handling Multiple Accounts

In today's interconnected world, GitHub has become an indispensable platform for developers and coders to collaborate on projects, contribute to open-source initiatives, and showcase their skills. However, what if you're like many of us, who wear multiple hats in the tech world? Managing more than one GitHub account on a single laptop can often feel like a tangled web of confusion and frustration. But fear not! In this blog, we'll unravel the mystery of seamlessly juggling multiple GitHub accounts, so you can effortlessly switch between personal projects, work-related repositories, and your open-source contributions, all from the comfort of your device. Whether you're a freelance developer, a student working on various coding assignments, or a professional with both personal and corporate coding needs, we've got you covered. Let's dive into the world of managing multiple GitHub accounts with ease and finesse!
Without more introduction, I'll move on to the next steps.
Create SSH keys for both accounts
Assuming you have already generated an SSH token from GitHub(if not follow these steps).
Register your keys with your respective accounts
Follow these steps to do so
Add the keys to your config file
Your laptop has an SSH config file in a .ssh directory. The config file is where you draw relations of your SSH keys to each GitHub account, and all your SSH keys generated are saved into the .ssh directory by default. You can navigate to it by running cd ~/.ssh (in Mac) or C:/User/.ssh (in Windows) within your terminal, open the config file with any editor, and add the below configuration:
#personal account
Host github.com-personal
HostName github.com
User git
IdentityFile ~/.ssh/github-user1
IdentitiesOnly yes
#work account
Host github.com-work
HostName github.com
User git
IdentityFile ~/.ssh/github-user2
IdentitiesOnly yes
Clone the repositories
Clone your repositories using the SSH URL from GitHub.
git clone git@github.com-personal:user1/your-repo-name.git
While cloning the SSH URL, replace the hostname(github.com) with the host which we added to our config file. In this case, I'm cloning my personal repository, so I replace github.com with github.com-personal.
Configure your git identity
Open up local git config using git config --local -e and add:
user]
name = user1
email = user1@gmail.com
Set remote URL
Run the below command to set the remote URL with the updated domain name
git remote set-url origin git@github.com-personal:user1/your-repo-name.git
That's it! Now you can perform the usual git operations like pull/push/fetch etc
By following the tips outlined in this guide, you can streamline your workflow and make the most of your GitHub experience. So, embrace the power of multi-account management and elevate your coding journey.
Happy coding!

