Developers often find themselves juggling more than one GitHub account — one for work and another for personal projects. While this is a great practice to maintain separation of concerns, it can lead to authentication issues and workflow hiccups if not properly configured.

In this article, we will walk through how to configure and manage multiple GitHub accounts on the same machine, allowing you to switch between them seamlessly.

Why You Might Need Multiple GitHub Accounts

There are several use cases for maintaining multiple GitHub accounts:

  • Personal vs. Work Projects: Avoid pushing sensitive code from work into personal repos or vice versa.

  • Freelancers or Consultants: Developers often work with multiple clients, each requiring access via different GitHub organizations.

  • Open Source Contributions: Sometimes you may wish to contribute anonymously or through a community-specific handle.

Managing all this on one system without conflicts requires a careful configuration of Git, SSH, and GitHub settings.

Create SSH Keys For Each Account

The first step in separating accounts is to use distinct SSH keys. GitHub uses SSH keys to identify you securely.

bash
# Generate SSH key for your personal GitHub account
ssh-keygen -t ed25519 -C "you@personal.com" -f ~/.ssh/id_ed25519_personal
# Generate SSH key for your work GitHub account
ssh-keygen -t ed25519 -C “you@work.com” -f ~/.ssh/id_ed25519_work

After running this command twice (once per account), you’ll have two SSH key pairs:

  • ~/.ssh/id_ed25519_personal and ~/.ssh/id_ed25519_personal.pub

  • ~/.ssh/id_ed25519_work and ~/.ssh/id_ed25519_work.pub

Add Your SSH Keys to the SSH Agent

Start the SSH agent in the background and add the keys.

bash

eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work

If you want this to persist across terminal sessions, include the commands in your shell config file (like ~/.bashrc or ~/.zshrc).

Add SSH Keys to GitHub Accounts

Go to GitHub > Settings > SSH and GPG keys for both accounts and add the corresponding .pub keys.

  • For personal GitHub: Paste the content of ~/.ssh/id_ed25519_personal.pub

  • For work GitHub: Paste the content of ~/.ssh/id_ed25519_work.pub

Give them meaningful titles like “Personal Laptop” or “Work Dev Machine”.

Configure the SSH Config File

Create or edit your ~/.ssh/config file to define aliases for GitHub.

bash
# Personal GitHub account
Host github-personal
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_personal
# Work GitHub account
Host github-work
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_work

This allows Git to determine which key to use based on the Host alias.

Clone Repositories Using Aliased Hosts

You must now clone repositories using the alias defined in your SSH config:

bash
# Cloning a personal repo
git clone git@github-personal:username/repo-name.git
# Cloning a work repo
git clone git@github-work:orgname/repo-name.git

Using the alias ensures Git picks the right SSH key, eliminating credential conflicts.

Configure Git User Info Per Repository

Set the correct Git identity on a per-repository basis:

bash
# Navigate into your repo
cd ~/projects/personal-repo
# Set personal Git identity
git config user.name “Personal Name”
git config user.email “you@personal.com”

For a work repo:

bash
cd ~/projects/work-repo
git config user.name "Work Name"
git config user.email "you@work.com"

This ensures your commits reflect the correct identity.

Set Up Global Git Configuration Defaults

You can also set a global identity (preferably personal) and override it per repo:

bash
# Global Git identity (default)
git config --global user.name "Personal Name"
git config --global user.email "you@personal.com"

This is particularly useful if most of your activity is from one account, and you override only for the other.

Use GitHub CLI with Multiple Accounts

The GitHub CLI (gh) can also handle multiple accounts, but requires configuration. Here’s how:

bash
gh auth login

You’ll be prompted to select an account and authenticate via browser or SSH.

For multiple accounts, you can create separate GitHub CLI configurations using environment variables:

bash
# For personal
GITHUB_TOKEN=ghp_xxxxxxx PERSONAL_GH_HOST=github.com gh api user
# For work
GITHUB_TOKEN=ghp_yyyyyyy WORK_GH_HOST=github.com gh api user

Managing tokens in .bashrc or using a tool like direnv can help separate environments cleanly.

Script Git Setup Per Project

To reduce setup friction, create a helper script to initialize new repositories with the correct settings.

bash

#!/bin/bash

# Usage: ./init-repo.sh personal my-new-repo
ACCOUNT=$1
REPO=$2

if [ $ACCOUNT” == “personal” ]; then
git clone git@github-personal:username/$REPO.git
cd $REPO
git config user.name “Personal Name”
git config user.email “you@personal.com”
elif [ $ACCOUNT” == “work” ]; then
git clone git@github-work:orgname/$REPO.git
cd $REPO
git config user.name “Work Name”
git config user.email “you@work.com”
fi

Make the script executable and use it whenever you start a new project.

Troubleshooting and Tips

Here are some common pitfalls and how to solve them:

  • Permission Denied (publickey): Make sure the correct SSH key is added and GitHub knows about it.

  • Wrong Identity Used in Commits: Always verify git config user.email before pushing.

  • Cloning with https:// Instead of git@: GitHub web interface may default to HTTPS. Always switch to SSH for proper key handling.

  • Credential Caching Issues: Disable credential helpers if they’re interfering:

bash
git config --global --unset credential.helper

Conclusion

Managing multiple GitHub accounts on the same system may seem complex at first, but with the right setup using SSH aliases, Git configurations, and repository-specific settings, the experience becomes seamless. The key lies in clear separation of identities and authentication methods:

  • Generate separate SSH keys per account.

  • Use the ~/.ssh/config file to route connections based on the GitHub alias.

  • Always set Git user.name and user.email per project to ensure commit accuracy.

  • Optionally, use scripts and tools like the GitHub CLI to automate the workflow and reduce manual errors.

By establishing these boundaries early, developers avoid the common pitfalls of mixing identities, pushing code under the wrong account, or encountering SSH errors mid-workflow. This approach is especially vital for those who balance open source, freelancing, and full-time employment — where account context is more than just a convenience, it’s a necessity.

With this configuration in place, you can confidently push, pull, and collaborate across your GitHub accounts without constantly worrying about authentication issues. Investing a little time upfront in setting this up will pay off in a cleaner, more professional development workflow.