4

I am trying to set the personal access token in VS code, but it doesn't seem to accept it. I put it in the "Github: Set Personal Access Token" in the command palette but it doesn't seem to have any effect. I also put the token in the Windows Credentials manager.

When I try to push, I get this error:

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: unable to access 'https://<usr>:token@github.com/<us>/repository.git/': The requested URL returned error: 403
Timothy G.
  • 6,335
  • 7
  • 30
  • 46
Bill Ferster
  • 347
  • 1
  • 5
  • 17
  • **See Also**: [How to add github personal access token to visual studio code](https://stackoverflow.com/q/66231282/1366033) – KyleMit Aug 22 '21 at 14:08

3 Answers3

2

Make sure you have the latest Git for Windows, and the git config --global credential.helper set to manager-core.

From there, check you do have indeed the token as password stored in the credential helper, using a CMD (not git bash):

printf "protocol=https\nhost=github.com"|"C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe" get
protocol=https
host=github.com
username=VonC
password=ghp_Dxc...<yourToken>

Make sure that token starts with ghp_ (following the new token format update).

If not, remove it:

printf "protocol=https\nhost=github.com"|"C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe" earase

Then the next push will ask and store your new credentials.
No need to manually tweak the Windows Credential Manager: that is what those helpers are for.

From the discussion, the problem was twofold:

  • The System User Windows path did not reference the Git installation path
  • The remote URL registered in the local repository did include directly the token (instead of relying on the git credential manager)

Solving those two issues allowed VSCode to start pushing with the proper credentials.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I re-installed a new version of git, set the credential.helper to manager-core, there doesn't seem to be that file there: C:\Users/bfers/git/gitcpl>printf "protocol=https/nhost=github.com"|"C:\Program Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe" get bash: C:Users/bfers/git/gitcpl: No such file or directory fatal: Missing 'protocol' input argument. My git file is .git, and it failed when I added the dot – Bill Ferster Aug 15 '21 at 15:02
  • @BillFerster Sorry, `C:\Users\\git\gitcpl` was just the folder I was in when I typed the `printf/git-credential-manager-core.exe` command. You can execute it in any folder you want. But in a CMD. Not in a git bash. – VonC Aug 15 '21 at 15:09
  • My toke is indeed "ghp..." Sorry to be dense, but how would I write that file to my desktop? – Bill Ferster Aug 15 '21 at 15:19
  • @BillFerster Make sure you have remove old github.com entries (if `git-credential-manager-core.exe get` shows you old password. Then the next `git push` will prompt you for your new credentials and cache them. Use your GitHub account name and token. – VonC Aug 15 '21 at 15:21
  • @BillFerster VSCode will "know" of the token simply because it will use the same credential helper than in CLI: the manager-core. – VonC Aug 15 '21 at 15:22
  • $ git-credential-manager-core.exe get bash: git-credential-manager-core.exe: command not found – Bill Ferster Aug 15 '21 at 15:26
  • @BillFerster bash? I remember stating in a past command: CMD only, no git bash. And use the full path of the executable in that CMD, as shown in the answer. – VonC Aug 15 '21 at 15:27
  • @BillFerster No need for VSCode terminal: let's make it right in a simple CMD. Then VSCode will work. – VonC Aug 15 '21 at 15:27
  • Failed to locate 'git.exe' executable on the path. – Bill Ferster Aug 15 '21 at 15:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/236027/discussion-between-vonc-and-bill-ferster). – VonC Aug 15 '21 at 15:56
2

If you have Windows 10, search for "Manage network passwords" - it takes you to open the Credential Manager in the Control Panel. Find git:https://github.com in the list (not GitHub - https://api.github.com/username) and change the password to the personal access token you create on the GitHub site.

I was able to push normally using the GitHub integration in VS Code after doing this.

nCardot
  • 5,992
  • 6
  • 47
  • 83
0

Are there too many cloned repositories?

Storing the token globally will be easy to use.

If you have a lot of cloned repositories on your machine, I think the best way is to store the Github token in git credential.helper globally.

Assuming you have a token handy and are trying to run any git command that needs authentication, even within VSCode, the steps are:

  1. Enter your username;
  2. Enter the previously generated token as the password in the password field;
  3. Run the command to retain the token in the credential.helper cache;

Command to step 3:

git config --global credential.helper cache

To clear the token from the local computer:

git config --global --unset credential.helper

There is a concern with credential caching related to how long the token is stored. To control this time it is necessary to set the "timeout" parameter or change the strategy to permanently store the credentials by changing the "cache" to "store" like this:

Complement command to step 3 (timeout in seconds):

# timeout default is 900 seconds
git config --global --set credential.helper 'cache --timeout=3600'

Command to step 3 (permanent storage):

git config --global credential.helper store

Using this helper will store your passwords/token unencrypted on disk, protected only by filesystem permissions.

Useful references:

André Carvalho
  • 927
  • 6
  • 12