Productivity

Managing Multiple GitHub Accounts Like a Pro

November 19, 20257 min read

Many developers juggle personal and work GitHub accounts. Managing them properly ensures your commits go to the right profile and you don't accidentally push work code to personal repos (or vice versa). Here's how to set it up correctly.

Step 1: Generate SSH Keys

Create separate SSH keys for each account:

# Generate key for personal account
ssh-keygen -t ed25519 -C "[email protected]" \
  -f ~/.ssh/id_ed25519_personal

# Generate key for work account
ssh-keygen -t ed25519 -C "[email protected]" \
  -f ~/.ssh/id_ed25519_work

Step 2: Add Keys to GitHub

Copy each public key and add it to the respective GitHub account:

# Copy personal key
cat ~/.ssh/id_ed25519_personal.pub | pbcopy

# Copy work key
cat ~/.ssh/id_ed25519_work.pub | pbcopy

Go to GitHub → Settings → SSH and GPG keys → New SSH key

Step 3: Configure SSH Config

Create or edit ~/.ssh/config:

# Personal GitHub
Host github.com-personal
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_personal
  IdentitiesOnly yes

# Work GitHub
Host github.com-work
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_work
  IdentitiesOnly yes

Step 4: Configure Git for Each Repo

Set up directory-based git configs. Edit ~/.gitconfig:

[user]
  name = Your Name
  email = [email protected]

[includeIf "gitdir:~/work/"]
  path = ~/.gitconfig-work

Then create ~/.gitconfig-work:

[user]
  name = Your Name
  email = [email protected]

Cloning Repositories

Use the custom host when cloning:

# Personal repos
git clone [email protected]:username/repo.git

# Work repos
git clone [email protected]:company/repo.git

Quick Verification

Test your SSH connections:

ssh -T [email protected]
# Hi username! You've authenticated...

ssh -T [email protected]
# Hi work-username! You've authenticated...

⚠️ Common Pitfall

Always verify which account you're using before pushing! Run git config user.email in your repo to confirm the correct email is set.