I am using Git on Linux. I followed this to create a Personal Access Token but forgot to save it. Therefore, when I was asked to enter the "password" again, I deleted the old PAT and created a new PAT. For some reason, the new token is rejected and I get
fatal: Authentication failed for 'https://github.com/username/***.git/'
When I look at the tokens page on github, this token says it was never used. What might be the issue here?
The issue might be with your current credential helper.
Type git config credential.helper
to see which one is used.
Type:
printf "protocol=https\nhost=github.com"|git-credential-xxx erase
(Replace xxx
by the credential helper name from the first command output)
That will clear out the cached credentials for https://github.com
.
Then try again a git push
, and see if it asks you for your credentials: enter your new PAT as password.
If you don't have a credential helper, I suggest installing microsoft/Git-Credential-Manager-Core
(there is a Linux package).
Add a credential store, and you are set.
After discussion:
I would therefore use a store credential caching:
git config --global credential.helper 'store --file /home/<user>/.my-credentials
Then:
git ls-remote https://github.com/<user>/<repo>
That will trigger the prompt for your username and token.
Edit /home/<user>/.my-credentials
and make sure the right token is in it.
Alternatively,
git config --global credential.helper 'store --file /home/<user>/.my-credentials'
and then:
git ls-remote https://<user>:<token>@github.com/<user>/<repo>
has worked.