Set github personal access token in visual studio code

Viewed 5518

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
3 Answers

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.

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.

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:

Related