N
Naveenr.dev
Chapter 00
4 min read

git-multiple-account

Managing Multiple GitHub Accounts on One Machine

As developers, we often need to use both a personal GitHub account and a professional GitHub account on the same laptop. If not configured properly, you may encounter issues such as:

  • Git pushing to the wrong account
  • Repository access errors
  • SAML SSO authentication failures
  • Commits showing under the wrong GitHub profile
  • SSH authentication using the incorrect key

In this blog, I'll walk through a practical setup using:

  • Personal GitHub Account
  • Professional GitHub Account
  • SSH Authentication
  • Separate SSH Keys
  • Git Identity Management

Understanding the Difference

A common misconception is that SSH authentication and Git commit identity are the same thing.

They are actually different.

SSH Authentication

Determines which GitHub account is used to access and push repositories.

Example:

git@work-github:organization/repository.git

Git Commit Identity

Determines who authored the commit.

Example:

git config user.name
git config user.email

GitHub uses the configured email address to associate commits with a GitHub profile.

Step 1: Generate Separate SSH Keys

Professional Account

ssh-keygen -t ed25519 -C "work-email@example.com"

Save as:

~/.ssh/id_work

Personal Account

ssh-keygen -t ed25519 -C "personal-email@example.com"

Save as:

~/.ssh/id_personal

Step 2: Add SSH Keys to GitHub

Professional Key

cat ~/.ssh/id_work.pub

Add it to:

GitHub → Settings → SSH and GPG Keys

Personal Key

cat ~/.ssh/id_personal.pub

Add it to your personal GitHub account.

Step 3: Configure SSH

Edit:

nano ~/.ssh/config

Add:

Host work-github
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_work
    AddKeysToAgent yes
    IdentitiesOnly yes

Host personal-github
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_personal
    AddKeysToAgent yes
    IdentitiesOnly yes

Step 4: Test Connections

Professional Account

ssh -T git@work-github

Personal Account

ssh -T git@personal-github

You should see a successful authentication message for both accounts.

Step 5: Clone Repositories Correctly

Professional Repository

git clone git@work-github:organization/project.git

Personal Repository

git clone git@personal-github:username/my-project.git

Step 6: Update Existing Repositories

If a repository was cloned previously with the wrong remote URL, update it:

git remote set-url origin git@work-github:organization/project.git

Verify:

git remote -v

Expected output:

origin  git@work-github:organization/project.git (fetch)
origin  git@work-github:organization/project.git (push)

Step 7: Configure Commit Identity

Default Git Identity

Configure the identity you use most frequently:

git config --global user.name "Your Name"
git config --global user.email "default-email@example.com"

Repository-Specific Identity

For repositories that require a different identity:

git config user.name "Your Name"
git config user.email "alternate-email@example.com"

This change applies only to the current repository.

Verifying Before Commit

Check the configured identity:

git config user.name
git config user.email

Check the remote URL:

git remote -v

Check SSH authentication:

ssh -T git@work-github
ssh -T git@personal-github

Common Errors and Fixes

SAML SSO Error

The organization has enabled or enforced SAML SSO

Fix:

  • Add your SSH key to GitHub
  • Authorize the key for your organization
  • Reauthenticate if required

Repository Not Found

ERROR: Repository not found

Possible causes:

  • Incorrect repository URL
  • Missing repository access
  • Wrong SSH alias being used

Verify the remote URL and SSH authentication.

Wrong GitHub User Appears

Check:

git config user.email

GitHub associates commits with the email address configured in the commit metadata.

Best Practices

  • Use separate SSH keys for each GitHub account.
  • Use SSH aliases to avoid authentication conflicts.
  • Verify your Git identity before committing code.
  • Keep personal and professional repositories separate.
  • Configure repository-specific identities when necessary.

Final Thoughts

Managing multiple GitHub accounts becomes effortless once you understand the difference between:

  1. SSH Authentication – Which account accesses the repository.
  2. Git Identity – Who authored the commit.

A recommended setup is:

  • work-github SSH alias → Professional repositories
  • personal-github SSH alias → Personal repositories
  • Default Git identity → Most frequently used account
  • Repository-specific Git identity → When different author information is needed

This approach eliminates authentication conflicts, prevents accidental commits from the wrong account, and makes switching between personal and professional projects seamless.

Enjoyed this chapter?

Get an email when I publish the next chapter. No spam — just new technical deep-dives.

Comments

Share feedback or questions about this blog post.

No comments yet. Be the first to share your thoughts.