{"id":84,"date":"2026-01-18T18:55:45","date_gmt":"2026-01-18T18:55:45","guid":{"rendered":"https:\/\/balamurali.in\/blog\/?p=84"},"modified":"2026-02-23T14:25:47","modified_gmt":"2026-02-23T14:25:47","slug":"how-to-manage-multiple-github-accounts-on-one-machine-the-pain-free-way","status":"publish","type":"post","link":"https:\/\/balamurali.in\/blog\/learn-with-me\/how-to-manage-multiple-github-accounts-on-one-machine-the-pain-free-way\/","title":{"rendered":"How to Manage Multiple GitHub Accounts on One Machine (The Pain-Free Way)"},"content":{"rendered":"\n<p>If you are like most developers, you probably have two lives: your day job and your side hustles.<\/p>\n\n\n\n<p>This usually means you have two GitHub accounts:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>A Work Account<\/strong> (e.g., specific to your organization)<\/li>\n\n\n\n<li><strong>A Personal Account<\/strong> (for your open-source contributions and hobby projects)<\/li>\n<\/ol>\n\n\n\n<p>The problem arises when you try to use both on the same laptop. You might push code to a personal repo only to realize later that the commit author is your work email. Even worse, you might encounter &#8220;Permission Denied&#8221; or &#8220;Repository Not Found&#8221; errors because Git is trying to authenticate your work repo using your personal SSH key.<\/p>\n\n\n\n<p>Manually switching SSH keys or configuring local git settings for every single repository is tedious and prone to error.<\/p>\n\n\n\n<p>In this post, I\u2019ll show you a &#8220;set it and forget it&#8221; folder management strategy that automatically switches your Git identity and SSH keys based on where your project lives.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Goal: Zero Manual Intervention<\/h2>\n\n\n\n<p>By the end of this guide, your workflow will look like this:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Any project inside <code>~\/Work\/<\/code> automatically uses your <strong>Work Identity<\/strong> and <strong>Work SSH Key<\/strong>.<\/li>\n\n\n\n<li>Any project inside <code>~\/Personal\/<\/code> automatically uses your <strong>Personal Identity<\/strong> and <strong>Personal SSH Key<\/strong>.<\/li>\n\n\n\n<li>You can clone using HTTPS or SSH, and it will just work.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Organize Your Directory Structure<\/h2>\n\n\n\n<p>The secret sauce here is <strong>folder-based configuration<\/strong>. To make this work, you need to separate your projects physically on your disk.<\/p>\n\n\n\n<p>Create two distinct directories:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir ~\/Personal\nmkdir ~\/Work<\/code><\/pre>\n\n\n\n<p>Move your existing projects into the appropriate folders.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Generate Separate SSH Keys<\/h2>\n\n\n\n<p>If you haven&#8217;t already, generate unique SSH keys for each account.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Generate Personal Key\nssh-keygen -t rsa -b 4096 -C \"your-personal-email@example.com\" -f ~\/.ssh\/id_rsa_personal\n\n# Generate Work Key\nssh-keygen -t rsa -b 4096 -C \"your-work-email@company.com\" -f ~\/.ssh\/id_rsa_work<\/code><\/pre>\n\n\n\n<p>Once generated, add the <strong>public keys<\/strong> (<code>.pub<\/code> files) to the respective GitHub accounts under <strong>Settings &gt; SSH and GPG keys<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Configure SSH Config<\/h2>\n\n\n\n<p>Now, tell your computer which key to use for which &#8220;host alias.&#8221; Edit your <code>~\/.ssh\/config<\/code> file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Personal Account\nHost github.com-personal\n    HostName github.com\n    User git\n    IdentityFile ~\/.ssh\/id_rsa_personal\n    IdentitiesOnly yes\n\n# Work Account\nHost github.com-work\n    HostName github.com\n    User git\n    IdentityFile ~\/.ssh\/id_rsa_work\n    IdentitiesOnly yes<\/code><\/pre>\n\n\n\n<p><em>Note: The <code>Host<\/code> value here acts as an alias we will use in the next step.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 4: The Magic of <code>.gitconfig<\/code> IncludeIf<\/h2>\n\n\n\n<p>This is the most critical part. Instead of putting all your settings in one global <code>.gitconfig<\/code> file, we will split them up using the <code>[includeIf]<\/code> directive.<\/p>\n\n\n\n<p>Open your main global config (<code>~\/.gitconfig<\/code>) and add this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user]\n    # Default global user (fallback)\n    email = default@example.com\n    name = Default Name\n\n&#91;includeIf \"gitdir:~\/Personal\/\"]\n    path = ~\/.gitconfig-personal\n\n&#91;includeIf \"gitdir:~\/Work\/\"]\n    path = ~\/.gitconfig-work<\/code><\/pre>\n\n\n\n<p>This tells Git: <em>&#8220;If I am inside the <code>~\/Personal\/<\/code> folder, load the extra settings from <code>.gitconfig-personal<\/code>.&#8221;<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 5: Create the Specific Config Files<\/h2>\n\n\n\n<p>Now, create the two specific configuration files referenced above.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>~\/.gitconfig-personal<\/code><\/h3>\n\n\n\n<p>This file ensures that any repo in your personal folder uses your personal email and automatically maps URLs to the correct SSH key alias.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user]\n    name = Your Personal Name\n    email = your-personal-email@example.com\n\n# Auto-rewrite URLs to use the specific SSH alias<\/code><\/pre>\n\n\n<p>[url &#8220;git@github.com-personal:&#8221;]<\/p>\n\n\n\n<p>insteadOf = git@github.com: insteadOf = https:\/\/github.com\/<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><code>~\/.gitconfig-work<\/code><\/h3>\n\n\n\n<p>Do the same for your work profile.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;user]\n    name = Your Work Name\n    email = your-work-email@company.com\n\n# Auto-rewrite URLs to use the specific SSH alias<\/code><\/pre>\n\n\n<p>[url &#8220;git@github.com-work:&#8221;]<\/p>\n\n\n\n<p>insteadOf = git@github.com: insteadOf = https:\/\/github.com\/<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How It Works Under the Hood<\/h2>\n\n\n\n<p>The magic lies in the <code>[url \"...\"] insteadOf<\/code> block.<\/p>\n\n\n\n<p>When you run <code>git push<\/code> inside <code>~\/Work\/ProjectA<\/code>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Git sees the <code>includeIf<\/code> matches <code>~\/Work\/<\/code>.<\/li>\n\n\n\n<li>It loads <code>.gitconfig-work<\/code>.<\/li>\n\n\n\n<li>It sets your author email to your work address.<\/li>\n\n\n\n<li>If you cloned the repo using <code>https:\/\/github.com\/org\/repo.git<\/code> or <code>git@github.com:org\/repo.git<\/code>, Git automatically rewrites the remote URL to <code>git@github.com-work:org\/repo.git<\/code>.<\/li>\n\n\n\n<li>The SSH config sees <code>github.com-work<\/code> and uses <code>id_rsa_work<\/code>.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">Summary Table<\/h2>\n\n\n\n<p>Here is a quick breakdown of how the environment handles your data:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">Folder Location<\/th><th class=\"has-text-align-left\" data-align=\"left\">Git User Identity<\/th><th class=\"has-text-align-left\" data-align=\"left\">SSH Key Used<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>~\/Personal\/*<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">Personal Name &amp; Email<\/td><td class=\"has-text-align-left\" data-align=\"left\"><code>id_rsa_personal<\/code><\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\"><code>~\/Work\/*<\/code><\/td><td class=\"has-text-align-left\" data-align=\"left\">Work Name &amp; Email<\/td><td class=\"has-text-align-left\" data-align=\"left\"><code>id_rsa_work<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>By spending 10 minutes setting this up, you save yourself from:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Accidentally committing to work repos with a personal email.<\/li>\n\n\n\n<li>Debugging SSH permission errors.<\/li>\n\n\n\n<li>Having to manually configure <code>git config user.email<\/code> for every new repository you clone.<\/li>\n<\/ul>\n\n\n\n<p>Just drag your project into the right folder, and Git handles the rest!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are like most developers, you probably have two lives: your day job and your side hustles. This usually means you have two GitHub accounts: The problem arises when&#8230;<\/p>\n","protected":false},"author":1,"featured_media":145,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[8],"tags":[],"class_list":["post-84","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-learn-with-me"],"jetpack_featured_media_url":"https:\/\/balamurali.in\/blog\/wp-content\/uploads\/2026\/02\/github_multiple_accounts.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":1,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/posts\/84\/revisions\/86"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/media\/145"}],"wp:attachment":[{"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/balamurali.in\/blog\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}