How do you reset the stored credentials in 'git credential-osxkeychain'?

MacosGitGithub

Macos Problem Overview


I've followed the GitHub instructions for setting up my account, and I'm able to clone, but I'm unable to push remotely.

When I do a "git push" I get the 403 error. It has the correct URL. I tried a "git credential-osxkeychain get" to see what it was giving, and this prints out the wrong credentials.

I believe what happened is the first time it asked for the credentials, I thought it was another application asking, and it put the wrong ones in.

I just need to reset it so that it uses the correct keychain item for my GitHub account.

I've tried:

git credential-osxkeychain erase
git credential-osxkeychain set

The program never gives any prompts. Set will say "bad input" if I don't do the right thing. I tried putting in "password=password", etc., but then when I do a "get" I still get the old ones.

I can't figure out where these are being stored, as they are not in .gitconfigure. Further there are no recent keychain items that could be it. (I have several GitHub accounts in my keychain and it is not using any of them.)

Macos Solutions


Solution 1 - Macos

From Terminal: (You need to enter the following three lines)

 $ git credential-osxkeychain erase ⏎
 host=github.com  ⏎
 protocol=https   ⏎
 ⏎
 ⏎

NOTE: after you enter “protocol=https” above you need to press RETURN TWICE (Each '⏎' is equivalent to a 'press enter/return' )

Solution 2 - Macos

I'm not sure how to erase through the command line, but it's fairly easily to do it through the Keychain Access app. Just go to Applications -> Utilties -> Keychain Access, then enter "github.com". You can either delete the invalid item or update the password from with the app.

Solution 3 - Macos

The solution turned out to be this:

The command git credential-osxkeychain was using the first GitHub account entry in my keychain. This one was not the one that had access to the projects in question.

I resolved the problem by touching the account in Keychain Access so that its date changed (I think I just changed the comment) and now that it became the most recent GitHub account it became the first one returned to credential-osxkeychain, and thus everything worked.

A better form of support for multiple GitHub accounts would be nice, but it is likely that most people only have one primary account and don't run into this problem.

Solution 4 - Macos

Try this in your command line.

git config --local credential.helper ""

It works for me every time when I have multiple GitHub accounts in OSX keychain

Solution 5 - Macos

git-credential-osxkeychain stores passwords in the Apple Keychain, as noted above.

By default, gitcredentials only considers the domain name. If you want Git to consider the full path (e.g. if you have multiple GitHub accounts), set the useHttpPath variable to true, as described at http://git-scm.com/docs/gitcredentials.html. Note that changing this setting will ask your credentials again for each URL.

Solution 6 - Macos

On Mac, use the command git credential-osxkeychain erase.

OR remove manually from keychain from ApplicationsUtilitiesKeychain Access. Then remove the github.com keychain. Then use push; it will ask for the keychain access; then deny.

It will ask for the new username and password, add it then pushes a file for that.

After git push I found this error. Then I use the upper case- issue:

> remote: Permission to user1/file.git denied to user2(previously exist > user ). fatal: unable to access 'https://github.com/xxxxxxxxxxxx/';: > The requested URL returned error: 403

Solution 7 - Macos

Try running /Applications/Utilities/Keychain Access.

Solution 8 - Macos

Solution 9 - Macos

You can delete existing credentials and add new ones via "Keychain Access"

Image

Ref. https://docs.github.com/en/github/getting-started-with-github/updating-credentials-from-the-macos-keychain

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnirvanaView Question on Stackoverflow
Solution 1 - MacosmazView Answer on Stackoverflow
Solution 2 - MacosbenzadoView Answer on Stackoverflow
Solution 3 - MacosnirvanaView Answer on Stackoverflow
Solution 4 - MacosinvinciblemuffiView Answer on Stackoverflow
Solution 5 - MacosMacFreekView Answer on Stackoverflow
Solution 6 - MacosAmit kumarView Answer on Stackoverflow
Solution 7 - MacosechristophersonView Answer on Stackoverflow
Solution 8 - MacosgorjanzView Answer on Stackoverflow
Solution 9 - MacosSatheezView Answer on Stackoverflow