3

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)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
daniel ernest
  • 345
  • 3
  • 9
  • 1. which "VSCode git-scm" plugin do you mean? (there are like hundreds) 2. git or github ? (need more details) – xerx593 Nov 13 '21 at 14:33
  • @xerx593 1. Please recall that I just pointed it to be "BUILT-IN" in VSCode. 2. giti failed to authenticate to GitHub, or did I miss a thing? – daniel ernest Nov 13 '21 at 15:52
  • Re *"returning authentication failed"*: What is the full error message? E.g., does it include *"remote: No anonymous write access."*? Please respond by [editing (changing) your question](https://stackoverflow.com/posts/69954625/edit), not here in comments (***without*** "Edit:", "Update:", or similar - the question should appear as if it was written today). – Peter Mortensen Nov 16 '21 at 22:58
  • This is a super [FAQ](https://en.wikipedia.org/wiki/FAQ) (because it affects so many). A candidate for the canonical question is *[fatal: Authentication failed for](https://stackoverflow.com/questions/69979522/)* (despite the unspecific title). – Peter Mortensen Nov 17 '21 at 23:02

1 Answers1

2

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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I don't know what is my `xxx` since `git config --global credential.helper` does not return anything. :( – Jaider Apr 20 '22 at 16:33
  • 1
    @Jaider Then, if you are on Windows, you can set it to manager-core. If not, install GCM (cross-platform): https://github.com/GitCredentialManager/git-credential-manager/#download-and-install= – VonC Apr 20 '22 at 17:29
  • Does a full tutorial for this exist for Windows users? Spent hours monkeying with this crap and still not getting anywhere. – MC9000 Jul 27 '22 at 11:10
  • 2
    @MC9000 The very same commands are working in a simple Windows CMD shell. I have edited the answer to explain how. – VonC Jul 27 '22 at 12:31
  • 1
    Weird I did exactly that, but my installation was corrupted, so I had to reinstall git. works fine now. Thanks! – MC9000 Jul 28 '22 at 23:47