If you maintain multiple GitHub accounts, for instance, one for personal projects, another for work or client projects, plus one or two for side projects or your own company, this setup allows you to keep them all on the same machine without any conflicts.
The benefits are:
- Your repos are divided by account,
- Git uses the right “commit name and email” depending on folder,
- SSH uses the right GitHub account when you clone, push or pull,
- Your main account (“acc1” in the screenshot above) can be your normal default,
- Adding a third, fourth, and so on, is just repeating this pattern.

Important Note About the Commands
The commands in this guide are written for a Bash-style shell.
That means they work as written in:
- Git Bash on Windows
- macOS Terminal
- Linux
If you are using PowerShell or Command Prompt, the overall setup still works, but the commands would need to be rewritten.
Big Idea
Each extra GitHub account gets four things:
- a parent folder where that account's repos live
- a small Git config file with that account's commit identity
- a dedicated SSH key
- a dedicated SSH alias
Your main/default GitHub account stays as your normal default setup.
So in practice:
- the folder determines which `user.name` and `user.email` Git uses for commits
- the SSH alias determines which GitHub account authenticates when cloning or pushing
You need both pieces.
Real-World Example
In this guide, we'll use example paths like:
Loading code block...
or on Mac/Linux:
Loading code block...
Those locations are just examples.
You can choose wherever you want to store:
- your repos
- your account-specific Git config files
- your SSH keys
A lot of people keep these somewhere simple, such as:
- inside their home folder
- inside `Documents`
- inside a general `Code`, `Repos`, or `Projects` folder
The exact folder names do not matter. What matters is that you:
- keep each extra account's repos inside its own parent folder
- keep your paths consistent
- use the same paths in the Git and SSH configuration steps
Replace These Placeholders
Loading table...
Step 1 — Choose a Parent Folder for That Account's Repos
Pick one folder where all repos for that GitHub account will live.
Example on Windows:
Loading code block...
Example on macOS/Linux:
Loading code block...
This folder name and location are arbitrary. You can choose a different one if you want.
Examples of perfectly fine alternatives:
- `C:/Users/donquix/Code/sanchop-repos`
- `C:/Users/donquix/Documents/GitHub-SideProjects`
- `/Users/donquix/code/sanchop`
- `/Users/donquix/repos/client-account-2`
Why this matters: Git will later use this folder path to decide which commit identity to apply automatically.
Step 2 — Choose a Place to Store Account-Specific Git Config Files
You also need a place to store small config files for each extra account.
Example on Windows:
Loading code block...
Example on macOS/Linux:
Loading code block...
Again, this location is arbitrary. Many people store these in:
- their home folder
- a `Documents` folder
- a `dotfiles`, `config`, or `git_accounts` folder
The only requirement is that you remember where you put them and use that exact path later.
Step 3 — Create a Git Config File for That Account
This file defines the Git commit identity for that extra account.
Windows example:
Loading code block...
macOS/Linux example:
Loading code block...
Check it:
Windows:
Loading code block...
macOS/Linux:
Loading code block...
This path is also arbitrary. Some people store files like this directly in their home folder, while others prefer a dedicated folder like `git_accounts`.
Why this matters: this file tells Git what name and email to use when making commits in repos for that account.
Important: this controls commit identity, not GitHub login/authentication. Authentication is handled later by SSH.
Step 4 — Tell Git When to Use That Identity
Now tell Git: "Whenever I'm inside repos under this folder, use that Git config file."
Windows example:
Loading code block...
macOS/Linux example:
Loading code block...
Check your global Git config:
Windows:
Loading code block...
macOS/Linux:
Loading code block...
You should see something like:
Loading code block...
or on macOS/Linux:
Loading code block...
Why this matters:
- your main account can stay your global default Git identity
- this rule overrides that identity only for repos inside the selected folder
So Git automatically switches commit identity based on where the repo lives.
Step 5 — Generate a Separate SSH Key for That Account
Now create a dedicated SSH key for the extra GitHub account.
Windows example:
Loading code block...
macOS/Linux example:
Loading code block...
You can use a passphrase if you want more security. If you want the simplest setup, you can leave it blank.
Why this matters: this key is how GitHub knows which account you are authenticating as over SSH.
Important: the `-C` email here is just a label on the SSH key. It does not control commit email.
Step 6 — Add the Key to Your SSH Agent
Windows with Git Bash, macOS, or Linux:
Loading code block...
If your key was saved in a different location, use that path instead.
Why this matters: the SSH agent keeps the key loaded so Git can use it without extra friction.
Step 7 — Add the Public Key to That GitHub Account
Show the public key:
Windows:
Loading code block...
macOS/Linux:
Loading code block...
Then:
- log into GitHub as `sanchop`
- go to Settings > SSH and GPG keys
- click New SSH key
- paste the public key
- save it
Why this matters: until the key is added to that GitHub account, GitHub will not recognize it.
Step 8 — Add an SSH Alias for That Account
Now add a custom SSH alias so you can explicitly route Git traffic for that account through the correct SSH key.
Open or create your SSH config file:
- Windows Git Bash: `C:/Users/donquix/.ssh/config`
- macOS/Linux: `~/.ssh/config`
Append this:
Loading code block...
Then check it:
Loading code block...
Why this matters:
- `github.com` is the real server
- `github-sanchop` is your personal shortcut/alias
- when you use `github-sanchop`, SSH uses the `sanchop` key
`IdentitiesOnly yes` helps make sure SSH uses this specific key instead of guessing from other keys loaded on your machine.
Step 9 — Test the SSH Connection
Loading code block...
You should get something like:
Loading code block...
Why this matters: it confirms that the alias is correctly routing you to GitHub using the intended account's key.
Step 10 — Clone Repos for That Account Using the Alias
Go to that account's parent repo folder and clone using the alias:
Windows example:
Loading code block...
macOS/Linux example:
Loading code block...
Then verify the Git identity:
Loading code block...
It should print:
Loading code block...
Why You Must Clone Future Repos Using the Alias
This is the part that usually confuses people, so here is the plain-English reason.
When you clone like this:
Loading code block...
you are using the default GitHub SSH host, which may use your main/default SSH identity.
When you clone like this:
Loading code block...
you are explicitly telling SSH: "Use my `github-sanchop` host rules, which means use the `sanchop` SSH key."
It doesn’t somehow “fix” the repo. It just uses the SSH remote with that host alias from the start, keeping authentication correct and predictable.
In short:
- folder location controls commit identity
- clone URL alias controls SSH authentication
Both matter.
Going Forward
For your main/default account
Keep using it normally.
Example:
Loading code block...
That continues using your normal default Git and SSH setup.
For each extra account
Do two things consistently:
- keep those repos inside that account's dedicated parent folder
- clone using that account's SSH alias
Example:
Loading code block...
That is the one habit that keeps everything clean.
Adding a Third or Fourth Account
Repeat the exact same pattern for each additional account.
Each one gets:
- its own parent repo folder
- its own small Git config file
- its own SSH key
- its own SSH alias
Loading table...
Nothing about the pattern changes.

