When git keeps asking for my password

Page content

Intro

Are you keeping your PowerShell code version controlled using git? Or any code for that matter. That’s great! Are you having problems accessing private repositories on GitHub or VSTS? Then this post if for you!

Git for Windows comes with this awesome component called Git Credential Manager for Windows. It keeps track of all your credentials by storing them in the Windows Credential Store AND it gives us support for multi-factor authentication for Visual Studio Team Services, GitHub and Bitbucket!

To download git for Windows I usually go to https://git-scm.com/download/win. You can get the same file from https://gitforwindows.org/. When installing git, make sure to check the box saying “Enable Git Credential Manager”, this will install and set up Git Credential Manager for Windows for you and all should work. Note “should”. Sometimes it just doesn’t and git keeps asking for your password. I’ve collected some tips for making it work again in this post.

Check if credential manager is installed

First off, make sure you actually have the credential manager installed by running:

git credential-manager version

This should give you something like:

Git Credential Manager for Windows version 1.16.2

This is the version included in git 2.18.0. To check the latest version of Credentail Manager available, simply head over to: https://github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/latest. When writing this, the latest version is 1.17.0.

Installing Git Credential Manager for Windows

If you don’t have git credential manager installed or you want to update to a newer version, you can get the .exe installer from the link above and just install it. The installer will verify that you have the required version of git and .Net framework and install it if its missing.

If you know that you already have git and .Net framework installed, you can grab the zip file instead and run the following in PowerShell from the folder where you downloaded the zip file to:

Unblock-File -Path .\gcmw-v1.17.0.zip
Expand-Archive -Path .\gcmw-v1.17.0.zip -DestinationPath .\gcmw
.\gcmw\git-credential-manager.exe install

Checking the version again should now result in a new version being installed.

Configure Git Credential Manager for Windows

Now we need to make sure git is configured to use the credential manager. Git configuration can be set in the scopes system, global and local, I’m going to use the global scope to effect all repositories for my user, you can replace global with system or local on any of the commands below to get a different scope. Let’s open the global configuration file.

git config --global --edit

This will open your global config file in your default editor. I like to use Visual Studio Code for this (can be selected during installation of git).

Verify that you have the following lines in your configuration:

[credential]
        helper = manager

This tells git to use the Git Credential Manager for Windows. To further investigate what happens, you can enable detailed logging by adding “writelog = true” to your file. This will make credential manager write detailed logs to your .git folder in each repository.

You can further configure settings for each remote service by adding an entry for each service like this:

[credential "github.com]
    authority = GitHub

[credential "simonwahlin.visualstudio.com"]
    authority = MSA

[credentail "contoso.visualstudio.com"]
    authority = AAD

This will configure git to use github auth for github.com, Live account for my personal simonwahlin remote and AzureAD account for the VSTS at contoso.

There are a whole lot of more options that can be configured, for a reference, check out the documentation. If you are having problem with access when using GUI applications for git, check out the setting “modalPrompt”.

Happy coding!