Git does not remember username and password on Windows
Git does not remember username and password…!
I was having issues, where Git would not remember my credentials for some repositories on Windows. Usually, the repositories are stored on AzureDevops and use Windows Authentication as default, with PAT (Personal Access Token) as a fallback.
In this case, since I am not an employee in the company, I was given a PAT. But git kept asking me to enter credentials for every operation against the repository origin and it was making me crazy that it was not remembering my credentials.
Make sure that you are using Windows Credentials manager
If you are using Git on Windows, you should store your credentials in the Windows Credentials manager, so they are properly encrypted and protected.
You can check this by running the following command in CMD or Powershell:
git config --list
It will then list all settings for git. You are looking for the credential.helper
which should be equal to manager
, eg. credential.helper=manager
.
Example:
... color.interactive=true help.format=html credential.helper=manager user.name=André Snede Kock user.email=andre@snede.net
Set credential helper
If it is not set, or you want to make sure it is. Run the following command to set the config on a global level.
git config --global credential.helper manager
And if you want a complete sanity check, you can unset it first via:
git config --global --unset credential.helper
Manually set the credentials in the Windows Credential Manager
Go to the Windows Credential manager, either by searching for it in Start:
Or finding it via the Control Panel -> Manage Windows Credentials.
Go to Windows Credentials -> Generic Credentials.
Here your credential should be listed if everything is working correctly. Git should add it by default the first time you log in to a new repository. But sometimes it doesn’t work.
Luckily for us, we can add our credential manually.
Check if your git repository credential is not already listed
A correct listing for github will look like the following:
Note that the internet or network address includes a git:
statement, this is important!
If you have an incorrect listing, remove it before continuing.
Manually add credential
In the Generic credentials listing, click “Add a generic credential”. This will take you to a new page, where you enter a url, username and password.
Make sure you remember to add “git:” to the start of the url.
That’s it! Now git should use these credentials by default.
You can now run
git pull or git clone https://snede.visualstudio.com
To test if it works. Depending on whether you have already downloaded the repo before.
Now git should remember your username and password, for that repository anyways.
Git does not automatically remember username and password, when the repository is using Windows Credentials for some reason.
Alternatively
If the username is already added and the above approach is not working, or not available to you, you can use the “run command” and open the key manager this way. This window is usually used for handling passwords in an automated way.
Windows Key + R – To Get the “Run” window up.
Then enter
rundll32.exe keymgr.dll,KRShowKeyMgr
This will allow you to edit, save or delete .NET Usernames and passwords. [Microsoft link]
// André Snede Kock
References:
https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage
https://stackoverflow.com/questions/15381198/remove-credentials-from-git
https://github.com/Microsoft/Git-Credential-Manager-for-Windows/issues/476
Everything is very open with a clear explanation of the challenges.
It was reallly informative. Your website is extremely helpful.
Thanks for sharing!
Excellent post. Very helpful !
Thank you and best of luck.
I have just forwarded this onto a colleague who had some trouble with this.
And he in fact ordered me breakfast because I stumbled upon it for him…
lol. So allow me to reword this…. Thanks for the meal!!
But yeah, thanks for spending time to share this !
This really was of great help!