daniel ernest
daniel ernest

Reputation: 454

Re-enable Visual Studio Code GitHub authentication

For absolutely no reason that I may think of, the Visual Studio Code built-in Git SCM stopped working, only returning authentication failed, not only in Visual Studio Code, but also in the terminal.

A weird thing is that last night it was working fine. Just to wonder today it’s not working any more.

By Visual Studio Code Git SCM stopped working I mean:

How can I re-enable the extension functionalities, without using email and password or appending access token before the remote URL path as specified here?

PS: I have the GitHub Copilot Git extension enabled and it’s authenticated properly in Git (properly working)

Upvotes: 3

Views: 10192

Answers (1)

VonC
VonC

Reputation: 1328982

Check first if your remote URL is an HTTPS one (in command-line: once this is working there, you can switch back to VSCode):

cd /path/to/repo
git remote -v

If HTTPS, check what credential helper is used to cache your credentials. An old password might be cached, which is no longer valid, since now only PAT (Personnal Access Token) are allowed (following the Aug. 2021 policy change).

The follwoing works, even in a simple Windows CMD shell (no git bash required), as long as you have set the PATH:

# For Windows only
# Replace C:\Program Files\Git by the folder path where your Git is installed
set "GH=C:\Program Files\Git"  
set "PATH=%GH%\bin;%GH%\cmd;%GH%\usr\bin;%GH%\mingw64\bin;%GH%\mingw64\libexec\git-core;%PATH%"

Then, from any shell you want, since Git PATH is referenced:

git config --global credential.helper
xxx
printf "host=github.com\nprotocol=https" | git-credential-xxx get

(replace xxx by the output of git config --global credential.helper)

If this is the wrong "password" (ie., not your current token), erase the old one and store the new one.

printf "host=github.com\nprotocol=https" | git-credential-xxx erase
printf "host=github.com\nprotocol=https\nusername=MyGitHubUserAccount\npassword=yyy" | git-credential-xxx store

(Again, printf works in a Windows CMD as well, if the %PATH% is set as mentioned before)

Upvotes: 2

Related Questions