Jekyll site on gh-pages: Authentication failed when pushing to gh-pages

I was following the instructions here (Creating a GitHub Pages site with Jekyll - GitHub Docs) for creating a Jekyll website. However, when I try running the command
git push -u origin gh-pages
I get the following error:

(base) arvindramaswami@arvinds-mbp % git push -u origin gh-pages                                             
remote: Invalid username or password.
fatal: Authentication failed for ''

I’m unsure why this is the case. It doesn’t even ask me to enter a username or password, but it’s telling me that my authentication has failed. And I don’t have any public SSH keys in your GitHub account, so I don’t think that’s the reason my push is failing. Does anyone have any pointers on what my bug could be? Thanks!

I think it might be due to the latest GitHub policies that require using a PAT (Private Access Token) to carry out Git operations, instead of the password — i.e. the password is used only to log into your GitHub account on the web, the PAT for all Git operations.

You need to generate a PAT in your account panel, and then use that instead of the password for Git credentials on all GitHub repositories (your username + PAT string instead of password).

That’s probably because your Git credentials have been already stored from your credentials manager. This has been the most common cause of Git operations on GitHub, since the PAT became mandatory.

Depending on your OS, credentials manager, Git tool (CLI vs GUI front-ends, etc.), you might have to look in different places to delete the old credentials, so that Git can ask you again for your GitHub credentials.

If you search the forum for “PAT” you’ll find many threads discussing this problem, with various instructions on how to solve it on different operating systems, credentials managers, etc.