git push asks for a password or uses the wrong account
Username for 'https://github.com':Git is asking you to sign in, because no sign-in helper answered. Or the push went through, but as the wrong GitHub account.
Why it happens
Section titled “Why it happens”- The GitHub account is not signed in to
gh. Devpit’s helper asksghfor the account’s token. If that account is signed out ingh, there is nothing to give Git, and Git asks you. - The remote is SSH, not HTTPS. A remote like
git@github.com:you/repo.gituses your SSH key, and the account that key belongs to. Devpit’s helper is not used. - The repository has its own helper. A
credential.helperset inside the repository comes first. Devpit shows it as “this repo’s own sign-in helper”. - Lines after Devpit’s block in your
~/.gitconfigcan win over its rules. Verify tells you which file wins. - A variable is set.
GH_TOKENorGITHUB_TOKENin the terminal makeghuse that token. - Devpit was uninstalled without cleanup. The helper line in Devpit’s rules file still points at a
devpit.exethat is gone.
How to fix it
Section titled “How to fix it”- In the repository folder, run
devpit accounts verify, which checks which GitHub account a push will use. In the app, the Pushes as row of the Git page says what decides it here: Devpit’s sign-in helper, Git’s own helper, this repo’s own helper, or the SSH key. - If the GitHub account is signed out, sign it in again with
gh auth login, then checkgh auth statuslists it. - Check the remote:
git remote -v. For an SSH remote, give the folder its own key, see SSH remotes. - Check the repository’s own helper:
git config --local --get-all credential.helper. - For one push as another account:
devpit github run work -- git push. - If you removed Devpit, reinstall it and run
devpit accounts cleanup, or delete the[include]block that namesrules.gitconfigat the end of your~/.gitconfig.
Never paste a token into a terminal or a file to make a push work. Sign in through gh and let the helper pass it.
Common questions
Does GitHub accept my account password for git push?
No. GitHub does not accept account passwords for Git over HTTPS. Git needs a token from a sign-in helper such as gh, Git Credential Manager or Devpit's helper, or an SSH key.
Which GitHub account does a push use?
Over HTTPS, the account the sign-in helper answers with. Over SSH, the account the SSH key belongs to. The Pushes as row on Devpit's Git page says which one decides in the folder.
