back to logs

MANAGING GIT CREDENTIALS FOR MULTIPLE GITHUB ACCOUNTS ON ONE MACHINE

Git is fine with one github account. two accounts on one laptop is where it gets messy — wrong email on commits, pushes that 404, ssh and https stepping on each other

the trick is to split three jobs and never let them share a login:

  • who wrote the commit → folder. ~/Projects is personal, ~/Otel is work
  • how work talks to github → ssh
  • how personal talks to github → https, saved in mac's keychain (osxkeychain)

mac + zsh here. bash is the same. linux: use libsecret instead of osxkeychain. windows: git bash / wsl and manager

aug 2026: gh auth login does not change your commit email. it does replace the https password git uses for github.com. i logged gh in as work, then git push from a personal repo said repository not found. fix: gh auth logout and let git fall back to osxkeychain. don't use gh to switch accounts.


0.5 why this and not gh

you can also: two ssh configs, swap emails by hand, or gh auth login / gh auth switch

two ssh keys means host aliases (github.com-work) and rewriting remotes. doable, noisy

gh looks like a switcher. it isn't. it stores one github.com user, and git https will use that user no matter which folder you're in. so we don't use it


1.0 two different questions

user.email is the name on the commit. ssh / https is who github lets into the repo. git does not keep those in sync. you can author as gmail and push as a totally different account

github only counts the commit toward your green squares if the email matches that account. the push still works either way

git can load a different email based on the folder:

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

inside ~/Projects you get the personal email. inside ~/Otel you get the work one. you don't type anything


2.0 folders and emails

mkdir -p ~/Otel
mkdir -p ~/Projects

personal is the default so a random repo outside ~/Otel doesn't commit as the company:

git config --global user.name "ojus"
git config --global user.email "guptaojas75@gmail.com"

~/.gitconfig-personal:

[user]
name = ojus
email = guptaojas75@gmail.com

~/.gitconfig-work:

[user]
name = ojus-otel
email = ojus@otelai.com

then at the bottom of ~/.gitconfig (the trailing slash matters):

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

check from inside a repo:

git config --show-origin user.email

~/Projects/www → gmail, from the personal file. an otel repo → ojus@otelai.com, from the work file


3.0 work — ssh

ssh-keygen -t ed25519 -C "ojus@otelai.com" -f ~/.ssh/id_ed25519_otel
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_otel
cat ~/.ssh/id_ed25519_otel.pub

paste that public key into the work github account → settings → ssh keys

tell ssh that github.com always uses this key. ~/.ssh/config:

Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519_otel
IdentitiesOnly yes

now every git@github.com:... clone is work. that's why personal repos stay on https — if you ssh a personal repo, github would see the work key

ssh -T git@github.com
cd ~/Otel
git clone git@github.com:OtelAI-Org/repo.git

4.0 personal — https + keychain

git config --global credential.helper osxkeychain

on github (personal account) → settings → developer settings → personal access tokens (classic). tick repo

clone with https. username is ojusxe. password is the token, not your github password:

cd ~/Projects
git clone https://github.com/ojusxe/repo.git

mac saves that as github.com / ojusxe. that's the only https login this laptop should have. work never uses it, because work is ssh


5.0 leave gh out of it

gh auth login writes one github user into the keyring. git https reads the same keyring. folders don't matter

what happened: gh logged in as work → personal git push used the work token → github said the repo wasn't there (it 404s instead of saying "wrong account")

logging gh out does not change your commit emails. it just stops gh from sitting on top of osxkeychain:

gh auth logout -h github.com

after that, gh auth status should say you're not logged in, and git config --global --get credential.helper should still be osxkeychain

if the next personal push asks for a password, paste a personal access token again. mac will remember it. don't run gh auth login to "fix" it


6.0 when something's off

wrong email on a commit
git config --show-origin user.email — if a repo has its own email, git config --local --unset user.email

https keeps asking for a password
git config --global credential.helper should print osxkeychain. if it's empty, run the command in 4.0 again

repository not found on a repo you own
https is logged in as the other person. gh auth status — if gh is logged in, log it out (5.0). don't switch the personal remote to ssh; github.com ssh is the work key

ssh says no
ssh-add -l — if the otel key isn't there, ssh-add ~/.ssh/id_ed25519_otel

folder email didn't switch
includeIf path must end with a slash (~/Projects/, ~/Otel/) and you have to be inside a git repo