The Easiest Way to Setup Two GitHub Accounts on One System
March 2, 2025Managing multiple GitHub accounts on a single computer sounds more complex than it actually is. In this blog, I will show the easiest way to get started with two separate GitHub accounts - one for personal projects and one for work. This segregation will keep your repositories organised and your credentials separate.
Organise Your Repository Folders
Create two folders on your system to keep your repositories distinct. For example, you might name them:
- Personal-Github
- Work-Github
Create a Global Git Configuration File
Within the parent folder that contains both repository folders, create a file named .gitconfig
. Add the following code to automatically include settings based on the directory you’re working in:
[includeIf "gitdir:~/Personal-Github/"]
path = ~/Personal-Github/.gitconfig
[includeIf "gitdir:~/Work-Github/"]
path = ~/Work-Github/.gitconfig
Generate SSH Keys for Each Account
Create separate SSH keys for your personal and work GitHub accounts.
- For your personal account, run this command:
ssh-keygen -t ed25519 -C "personal_email@example.com" -f ~/.ssh/id_ed25519_personal
- For your work account, run this command:
ssh-keygen -t ed25519 -C "work_email@example.com" -f ~/.ssh/id_ed25519_work
Add Your SSH Keys to the SSH Agent
Ensure your SSH keys are managed by the SSH agent with the following commands:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_personal
ssh-add ~/.ssh/id_ed25519_work
Upload Your SSH Keys to GitHub
To link your SSH keys with GitHub:
- Copy the public key for your personal account with this command:
cat ~/.ssh/id_ed25519_personal.pub
- Copy the public key for your work account with this command:
cat ~/.ssh/id_ed25519_work.pub
After copying each key, for each GitHub account, go to Settings > SSH and GPG keys > New SSH Key, and add the key.
Set Up a Local Git Configuration for Each Account
Within each folder, create a local .gitconfig file to specify your user information and SSH settings.
-
In your personal repositories folder (Personal-Github) create a
.gitconfig
file with the following code:[user] name = Your Personal Name email = personal_email@example.com [core] sshCommand = ssh -i ~/.ssh/id_ed25519_personal -F /dev/null
-
In your work repositories folder (Work-Github) create a
.gitconfig
file with the following code:[user] name = Your Work Name email = work_email@example.com [core] sshCommand = ssh -i ~/.ssh/id_ed25519_work -F /dev/null
Verify Your Configuration
Before cloning any repositories, check your configuration by navigating to each folder and running the following commands.
- For the personal repositories:
git config user.name # Should output your personal name git config user.email # Should output your personal email
- For the work repositories:
git config user.name # Should output your work name git config user.email # Should output your work email
Clone Repositories Using SSH
When cloning repositories, be sure to use the SSH URL rather than the HTTPS URL. For example:
git clone git@github.com:ProfileName/RepositoryName.git