Multi-Github accounts through terminal in 2026
Intro
I already got an older post for this topic.
That one still works, but config in old method consumed lot’s of time.
So I make a new one instead. By using latest gh-cli feature.
Main idea still same:
- let Git switch commit identity by folder
- let GitHub CLI handle GitHub login state
So Let’s go.
What changed from the old version
Skip this section , If you didn’t watch old post before
The old way I used before:
- manual create
hosts.ymland multiplehosts.yml.* - using the terminal command to copy file around when switching account
What changes?
- use
gh auth login - no need to config ton of
hosts.yml - no need to create a personal token of each github account
- use
gh auth switchto switch account
Git identity vs GitHub auth
This part is important.
People mix this up all the time.
user.name and user.email
is your commit identity.
gh auth login / gh auth switch
is your GitHub account login state.
These are not same thing.
If commit email is wrong,
go check .gitconfig
If gh command is using wrong account,
go check:
1 | gh auth status |
Now you know, ezpz.
Step by step setup
First, decide your folder layout.
I use something like this:
~/Projects/personal/~/Projects/work/
Then I let Git load different config by folder.
1 | ~/Projects/ |
Example .gitconfig
Put this in ~/.gitconfig
1 | [includeIf "gitdir:~/Projects/personal/"] |
~/.gitconfig is just the router.
The actual identity still lives in the per-account files.
Example ~/.gitconfig.personal
1 | [user] |
Example ~/.gitconfig.work
1 | [user] |
GitHub CLI multi-account setup
If you want to push your code, you still need the authentication for Github.
Here comes the Github-CLI.
1 | gh auth login |
Do it again for N-1 times if you got another account:
1 | gh auth login |
Usually it opens abrowser login.
Remember to Copy the code from the terminal,
I was confuse at first, When I saw the github website require me input some code..
Check current active account:
1 | gh auth status |
Switch account interactively:
1 | gh auth switch |
Switch directly to work account:
1 | gh auth switch --hostname github.com --user your-work-handle |
Switch directly to personal account:
1 | gh auth switch --hostname github.com --user your-personal-handle |
If you was to lazy, set alias for your terminal
put this into ~/.zshrc , then restart the terminal
1 | # github cli |
How to verify it works
Check personal repo:
1 | cd ~/Projects/personal/blog |
Check work repo:
1 | cd ~/Projects/work/internal-api |
Check current GitHub CLI account:
1 | gh auth status |
TL;DR
Suggested title: Multi-Github accounts in 2026
1 | # ~/.gitconfig |
1 | # ~/.gitconfig.personal |
1 | # ~/.gitconfig.work |
1 | gh auth login |