On at least two ocassions I’ve found myself scratching my head when an attempted push to a newly-created Github repo is met with authentication failures, despite me being sure I’m using the correct credentials.
Here’s the lowdown on the issue and how to resolve it.
Essentially the problem relates to Github expecting a personal access token rather than a password (although it provides no helpful hints that this is the case).
This might be because your Github account has 2FA enabled, and/or for security purposes because your account is part of an organisation that uses SAML single sign-on (SSO).
In my case, I had previously created a personal access token with the requisite privileges (in my Github account’s Developer Settings > Tokens section) for the purposes of API access, so I was able to just reuse that. However, if need be I could have created a new one.
Thanks to Ginny Fahs who had the same problem and documented her solution.
Github’s Help page Creating a personal access token for the command line is also useful.