git credentials

At work we use GitLab as our source code repository. GitLab is configured to use single sign-on with our corporate credentials, which means we have to use access tokens when using the git on the command line or in an IDE. The corporate policy is to use Windows rather than Linux.

When an access token expires, it is straight-forward to create a new token but the fun begins when trying to convince git to prompt for the credentials, as it will continue to use the cached old credentials resulting in the following error message:

git fetch
remote: HTTP Basic: Access denied. The provided password or token is incorrect or your account has 2FA enabled and you must use a personal access token instead of a password. See https://********/help/topics/git/troubleshooting_git#error-on-git-fetch-http-basic-access-denied
fatal: Authentication failed for 'https://********/'

The version of git installed on my laptop is "git version 2.38.1.windows.1" and the credential helper is configured as "manager-core". The credential helper is significant because different helpers store credentials in different ways and this appears to be a relative new helper and not mentioned often in online search results. It is also different to the helper I had used on my previous laptop, which stored the credentials in the Windows Credential Manager (from which expired tokens could be removed). It was not clear from the documentation where the manager-core credential helper stores credentials. However from the git documentation I could see that it should be possible to erase a credential from the helper, so the following worked for me:

git credential-manager-core erase
protocol=https
host=********
username=neil**

Note that there is a blank line at the end of the standard input.

Once the old credentials had been erased then any git command that interacted with the remote repository would trigger aprompt for the username and password. I assume that most credential helpers support the same syntax.