I\'m working with several repositories, but lately I was just working in our internal one and all was great.
Today I had to commit and push code into other one, but
What finally fixed this for me was to use GitHub desktop, go to repository settings, and remove user:pass@ from the repository url. Then, I attempted a push from the command line and was prompted for login credentials. After I put those in everything went back to normal. Both Visual Studio and command line are working, and of course, GitHub desktop.
GitHub Desktop->Repository->Repository Settings->Remote tab
Change Primary Remote Repository (origin) from:
https://pork@muffins@github.com/MyProject/MyProject.git
To:
https://github.com/MyProject/MyProject.git
Click "Save"
Credentials will be cleared.
Execute the following command in a PowerShell console to clear Git Credentials Managers for Windows cache:
rm $env:LOCALAPPDATA\GitCredentialManager\tenant.cache
or in Cmd.exe
rm %LOCALAPPDATA%\GitCredentialManager\tenant.cache
Building from @patthoyts's high-voted answer (https://stackoverflow.com/a/15382950/4401322):
His answer uses but doesn't explain "local" vs. "global" vs. "system" configs. The official git documentation for them is here and worth reading.
For example, I'm on Linux, and don't use a system config, so I never use a --system
flag, but do commonly need to differentiate between --local
and --global
configs.
My use case is I've got two Github crendentials; one for work, and one for play.
Here's how I would handle the problem:
$ cd work
# do and commit work
$ git push origin develop
# Possibly prompted for credentials if I haven't configured my remotes to automate that.
# We're assuming that now I've stored my "work" credentials with git's credential helper.
$ cd ~/play
# do and commit play
$ git push origin develop
remote: Permission to whilei/specs.git denied to whilei.
fatal: unable to access 'https://github.com/workname/specs.git/': The requested URL returned error: 403
# So here's where it goes down:
$ git config --list | grep cred
credential.helper=store # One of these is for _local_
credential.helper=store # And one is for _global_
$ git config --global --unset credential.helper
$ git config --list | grep cred
credential.helper=store # My _local_ config still specifies 'store'
$ git config --unset credential.helper
$ git push origin develop
Username for 'https://github.com': whilei
Password for 'https://whilei@github.com':
Counting objects: 3, done.
Delta compression using up to 12 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 1.10 KiB | 1.10 MiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: Resolving deltas: 100% (1/1), completed with 1 local object.
To https://github.com/whilei/specs.git
b2ca528..f64f065 master -> master
# Now let's turn credential-helping back on:
$ git config --global credential.helper "store"
$ git config credential.helper "store"
$ git config --list | grep cred
credential.helper=store # Put it back the way it was.
credential.helper=store
It's also worth noting that there are ways to avoid this problem altogether, for example, you can use ~/.ssh/config
's with associated SSH keys for Github (one for work, one for play) and correspondingly custom-named remote hosts to solve authentication contextualizing too.
I found something that worked for me. When I wrote my comment to the OP I had failed to check the system config file:
git config --system -l
shows a
credential.helper=!github --credentials
line. I unset it with
git config --system --unset credential.helper
and now the credentials are forgotten.
C:\Users\<current-user>
.git-credentials
fileTry using the below command.
git credential-manager
Here you can get various options to manage your credentials (check the below screen).
Or you can even directly try this command:
git credential-manager uninstall
This will start prompting for passwords again on each server interaction request.