1

I am unable to push to git after generating a new personal access token. I've looked around at similar questions but think that I may have a more fundamental misunderstanding of how this works.

I got an email saying passwords were being phased out, so I generate a token and could no longer push a repo I've been working on using my password. From the instructions it looked like I can use the token just like a password, but to no avail. This is what the error looks like:

enter image description here

where I have pasted my token when prompted for password. (I've blacked out my username.) I am on Windows 10 and having checked my credentials manager do not appear to have credentials stored for github at the moment.

My questions are:

  1. Ideas for immediate convenient fixes? I was seeing some suggestions about setting the remote-url, but a little concerned about doing this for every repo I have. I'd like to change my workflow minimally, if possible.

  2. I'm probably grossly misunderstanding the point of the token. What is the "correct" way to set up a workflow to github? (Including maybe big changes that might take me a weekend to set up correctly, in a few weeks from now, say.) Am I supposed to set up a 2FA? (Will this change my web login at all?) Why is this more secure than a password? I've currently not setup SSH or anything else, really.

blackraven
  • 5,284
  • 7
  • 19
  • 45
Tommy Tang
  • 25
  • 1
  • 4

2 Answers2

1

I followed a similar workflow, generating a new token (in github.com/settings/tokens), and using it as password without issues.

I just made sure:

  • its scope included repo, workflow, gist and user. (you can update those scopes without regenerating the token)
  • its expiration date was either not set, or set to a date far enough to allow me to test/use it.

The resulting token should start with ghp_

ghp_DUvWjre....(ghp_ followed by 36 alphanumerical chars)

The OP Tommy Tang confirms in the comments:

I didn't find a previous credential, so I just added a generic credential on the manager, and it works.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks - I tried that and changed the scope and ensured the expiration date was far into the future. But I still get the same error message. Persisted even after I generated a new token and repeated everything. Any ideas on what might be the issue? – Tommy Tang Sep 29 '21 at 22:56
  • @TommyTang Then check what `git config credential.helper` returns, and double-check (again) your Windows Credential Manager: something is caching, and providing the wrong password – VonC Sep 30 '21 at 06:37
  • Hmm, I didn't find a previous credential, so I just added a generic credential on the manager and it works. Thanks for your help! – Tommy Tang Sep 30 '21 at 20:29
  • @TommyTang Perfect, well done. I have included your comment in the answer for more visibility. – VonC Sep 30 '21 at 21:48
  • I've generated a personal access token several times, and whenever I try to use it like this I get the same error. – rodmclaughlin Oct 17 '21 at 09:20
  • tensorflow-towardsdatascience git:(master) ✗ git push --set-upstream origin master – rodmclaughlin Oct 17 '21 at 09:21
  • remote: Permission to pdxrod/tensorflow-towardsdatascience.git denied to pdxrod. fatal: unable to access 'https://github.com/pdxrod/tensorflow-towardsdatascience.git/': The requested URL returned error: 403 – rodmclaughlin Oct 17 '21 at 09:21
  • This is after using the technique of changing .git/config to contain url = https://pdxrod:ghp_Xyzetc@github.com/pdxrod/tensorflow-towardsdatascience.git – rodmclaughlin Oct 17 '21 at 09:23
  • @rodmclaughlin Did Git ask you for a password when you pushed, or did it immediately gave you the 403 error message? – VonC Oct 17 '21 at 20:19
  • It immediately gave me the 403 error message. However, I have found the solution. You have to click on 'repo' in the Access Token page on Github: https://mycyberuniverse.com/how-fix-fatal-authentication-failed-for-https-github-com.html – rodmclaughlin Oct 18 '21 at 22:56
  • @rodmclaughlin I do mention the repo scope though. Thank you to explain how to select said repo scope. – VonC Oct 19 '21 at 06:05
  • It also happens when git is not updated to latest version, run cmd and type `git update-git-for-windows` – blackraven May 04 '22 at 13:03
0

https://mycyberuniverse.com/how-fix-fatal-authentication-failed-for-https-github-com.html

After generating a new Personal Access Token, under 'Select Scopes', click on 'repo', then hit 'Generate new token'. This will give you a token which can be used to push code from the command line.

rodmclaughlin
  • 371
  • 3
  • 8