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 createhosts.yml and multiple hosts.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 switch to 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
2
3
4
5
6
7
8
9
~/Projects/
├── personal/
│ ├── blog/
│ ├── dotfiles/
│ └── random-side-project/
└── work/
├── internal-api/
├── dashboard/
└── infra-scripts/

Example .gitconfig

Put this in ~/.gitconfig

1
2
3
4
5
6
7
8
9
10
11
[includeIf "gitdir:~/Projects/personal/"]
path = ~/.gitconfig.personal

[includeIf "gitdir:~/Projects/work/"]
path = ~/.gitconfig.work

[pull]
rebase = true

[init]
defaultBranch = main

~/.gitconfig is just the router.
The actual identity still lives in the per-account files.

Example ~/.gitconfig.personal

1
2
3
[user]
name = Austin
email = austin.personal@example.com

Example ~/.gitconfig.work

1
2
3
[user]
name = Austin
email = austin@company.com

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
2
# github cli 
alias gas="gh auth switch"

How to verify it works

Check personal repo:

1
2
3
4
cd ~/Projects/personal/blog
git config user.name
git config user.email
git config --show-origin user.email

Check work repo:

1
2
3
4
cd ~/Projects/work/internal-api
git config user.name
git config user.email
git config --show-origin user.email

Check current GitHub CLI account:

1
gh auth status

TL;DR

Suggested title: Multi-Github accounts in 2026

1
2
3
4
5
6
# ~/.gitconfig
[includeIf "gitdir:~/Projects/personal/"]
path = ~/.gitconfig.personal

[includeIf "gitdir:~/Projects/work/"]
path = ~/.gitconfig.work
1
2
3
4
# ~/.gitconfig.personal
[user]
name = Austin
email = austin@gmail.com
1
2
3
4
# ~/.gitconfig.work
[user]
name = Austin
email = austin@company.com
1
2
3
gh auth login
gh auth status
gh auth switch