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.
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.
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.
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:
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:
For a work repo:
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:
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:
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:
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.
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 ofgit@
: 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:
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.