Authenticating to GitHub using Git for Windows and a Personal Access Token fails

While following this guide to migrate to using multiple GitHub HTTPS accounts on Windows from a single user account I have used for years, I had to remove my existing GitHub.com credentials from Windows Credential Manager. When re-authenticating via the prompted login window:

to existing repos on GitHub.com using an existing Personal Access Token or authenticating to a new repo using a different account on an instance of GitHub Enterprise using a new Personal Access Token, I would receive a combination of the following errors:

repository not found

login failed use ctrl+c to cancel basic credential prompt

Turns out the GitHub recently deprecated basic authentication using a username and password in favour of a personal access token. I couldn’t see why this was causing me an issue since I was trying to use a personal access token.

This StackOverflow post cleared things up. A later version of git for Windows is required in order to use the new method. Initially I had v2.27.0.windows.1 so upgraded to the latest as of writing this post v2.30.0.windows.2. There’s a clue to some changes during the upgrade process that a new Git Credential Manager will be used:

After upgrade there is a different dialogue window when authenticating:

Using the Personal Access Tokens were now successful for me across all repos in GitHub.com and Enterprise.

As a side note, if your GitHub Enterprise uses SSO for authentication then you will need to Enable SSO for you Personal Access Token

You may then be prompted further when accessing a repo for the first time to navigate to a URL to authorise it for that repo via a browser.