GitHub Windows Auth — Diagnose & Fix
Fix git push failures on Windows caused by stale credentials or mismatched GitHub accounts.
The pattern
On Windows, git uses the Windows Credential Manager as its credential store. When multiple GitHub accounts are in use (e.g. personal bmaltais and org bernardmaltais), the stored credential can belong to the wrong account — and gh auth switch alone doesn't fix it because git bypasses gh and reads the cached token directly.
The fix is always the same three steps:
- Clear the stale Windows credential
- Tell git to use
ghas its credential helper going forward - Push
Diagnostic process
Step 1 — Identify which account the remote needs
git -C <repo-path> remote get-url origin
The org/user in the URL tells you which gh account must be active.
Step 2 — Check which accounts gh knows about
gh auth status
Look for the account matching the remote. If it's not listed, authenticate it first:
gh auth login
Step 3 — Switch gh active account if needed
gh auth switch --user <username>
Step 4 — Clear stale Windows credential and wire gh as helper
cmdkey /delete:LegacyGeneric:target=git:https://github.com
gh auth setup-git
Step 5 — Push
git -C <repo-path> push
Notes
gh auth setup-gitwritesgh auth git-credentialas the credential helper in the global git config. It persists — you only need to run it once per machine (or aftercmdkey /deletewipes the old entry).- If you have two org accounts (e.g.
bmaltaisandbernardmaltais), the activeghaccount at push time determines which token git uses. Switch before pushing to the other org. - If
ghis not onPATHin the current shell, reload it first:$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","User") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","Machine")
Quick reference — full fix in one line
$env:PATH = [System.Environment]::GetEnvironmentVariable("PATH","User") + ";" + [System.Environment]::GetEnvironmentVariable("PATH","Machine")
gh auth switch --user <username>
cmdkey /delete:LegacyGeneric:target=git:https://github.com
gh auth setup-git
git -C <repo-path> push