Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • I use Ubuntu 21.04 (Hirsute Hippo), and I have two-factor authentication enabled in GitHub.
  • I tried to create a personal access token, but I can’t find anywhere to put it for Git SCM in Visual Studio Code to work correctly across all repositories without exposing it.

By Visual Studio Code Git SCM stopped working I mean:

  • Can't pull/push to a remote repository using the built-in Git extension in Visual Studio Code
  • Can't issue the clone command for private repositories

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)

like image 763
daniel ernest Avatar asked Feb 11 '26 12:02

daniel ernest


1 Answers

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)

like image 129
VonC Avatar answered Feb 13 '26 04:02

VonC