Git Push Permission Denied to the Wrong GitHub Account: Fix
When GitHub says Permission to org/repo denied to someone-else, your push reached the right server with the wrong account. Git offered the wrong SSH key or the wrong stored credential, so the fix is to make that choice explicit per repository, not to retry the push.
This is the classic side effect of owning more than one GitHub account on a single machine: personal, work, a client. Here is how to read the error, find which identity Git actually used, and fix it for good.
What does “Permission to repo denied to user” actually mean?
The message names two things: the repository you tried to push to, and the account GitHub thinks you are. The repository exists and your intended account may well have access. The account that authenticated does not.
Over SSH it looks like this:
ERROR: Permission to acme-inc/billing.git denied to personal-account.
fatal: Could not read from remote repository.
Over HTTPS you get the same information with a 403:
remote: Permission to acme-inc/billing.git denied to personal-account.
fatal: unable to access 'https://github.com/acme-inc/billing.git/': The requested URL returned error: 403
Do not confuse it with Permission denied (publickey). That one means GitHub did not recognize any key you offered. A “denied to user” error means a key or token was accepted, just for the wrong person. See GitHub’s own page on the publickey error for the other case.
Why does Git pick the wrong account?
Both of your accounts live at github.com. SSH sees one hostname, so it tries the keys your agent holds, in order, and GitHub accepts the first one it knows. If your personal key is loaded first, every repository is accessed as your personal account, including the client’s.
HTTPS has the same problem with a different cause: the macOS keychain stores one credential for github.com, and Git reuses it everywhere.
How do you find which identity Git used?
Check the three places that matter, in this order.
Which account does SSH authenticate as?
ssh -T git@github.com
GitHub answers Hi username! You've successfully authenticated. If that name is not the account you wanted for this repository, the key is the problem. Add -v to see which key files were offered.
Which remote and credentials does the repo use?
git remote -v
gh auth status
An https:// remote relies on stored credentials or the gh session. A git@github.com: remote relies on SSH keys. gh auth status lists every logged-in account and marks the active one.
Which identity will the commit carry?
git config --show-origin user.email
The --show-origin flag prints the file that supplied the value, which tells you whether a folder rule applied or the global default won.
How do you fix it for one repository right now?
Tell SSH to use exactly one key and ignore the agent’s other offers:
git config core.sshCommand "ssh -i ~/.ssh/id_ed25519_acme -o IdentitiesOnly=yes"
IdentitiesOnly=yes is the important part. Without it, SSH still tries every key in the agent first. If the remote is HTTPS, switch the gh session instead:
gh auth switch --user acme-account
How do you make it stick for every repo in a folder?
Stop fixing repositories one by one. Group them by folder and let Git choose from the path with a conditional include, available since Git 2.13 (documented here):
# ~/.gitconfig
[user]
name = Your Name
email = you@personal.dev
[includeIf "gitdir:~/clients/acme/"]
path = ~/.gitconfig-acme
# ~/.gitconfig-acme
[user]
email = you@acme.com
[core]
sshCommand = ssh -i ~/.ssh/id_ed25519_acme -o IdentitiesOnly=yes
Keep the trailing slash on the gitdir path, and put the includeIf after the default values so the included file wins. Every repository cloned under ~/clients/acme/ now uses the Acme email and the Acme key, today and next year.
This still leaves the gh session and commit signing, which includeIf does not switch. Our longer walkthrough, Multiple GitHub Accounts on One Mac, covers all four layers.
Can you stop it from happening again?
The pain is not the fix, it is forgetting. A pre-push check that compares the repository’s expected identity with the active one catches the mistake before GitHub does. Hats is a free menu bar app for macOS that binds folders to profiles, switches commit identity, SSH key, gh and signing together, and blocks the push when the hat is wrong.
FAQ
Why does GitHub say “denied to” an account I never use here?
Because your agent or keychain offered that account’s credentials first. Run ssh -T git@github.com to see which account it is, then pin the right key with IdentitiesOnly=yes.
Do I need separate SSH keys for each GitHub account?
Yes. GitHub does not allow the same SSH public key on two accounts, so each account needs its own key.
Does git config user.email change who I push as?
No. The email only labels your commits. Authentication comes from the SSH key or token, which is why a push can fail even when your commits look correct.
Why does the 403 persist after I switch accounts?
An HTTPS remote may still use a cached credential. Sign out the stale one from the keychain, or move the remote to SSH with git remote set-url origin git@github.com:acme-inc/billing.git.