59

I'm trying to push, pull, and whatever to my GitHub repository from Visual Studio Code.

I enter my username and password, but I'm getting the error:

Authentication failed on the git remote.

I just logged in on github.com with the same user/password. I tried creating a personal access token, using it as a password, but I got the same error.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
joakim
  • 1,494
  • 1
  • 13
  • 23
  • try to commit from command line and see if it works or not. If it does, then your VSCode settings might have issues. – Arunav Sanyal Sep 17 '15 at 20:30
  • Not sure how to use the command line. It's a fresh installation of VSCode and Git. I'm able to use the GitHub official windows client. – joakim Sep 17 '15 at 21:04
  • Download a client like Git Bash first. Use that as a replacement. Check out the git bash column in https://git-for-windows.github.io/. This would allow you to run this command : git push origin master – Arunav Sanyal Sep 17 '15 at 21:09
  • `git push origin master` from command line works fine. I allowed VSCode in Windows firewall. I'm not behind a proxy. Still it won't work. – joakim Sep 17 '15 at 23:00
  • 1
    Same here. Credentials work with command line, but not with VS Code. – Prabhu Dec 03 '15 at 16:34
  • If you are here from a search engine (e.g., matching "fatal authentication failed push GitHub repository") looking for a solution to the problems after the ***[Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code) update in November 2021*** (to version 1.62.2), then the candidate for the canonical question for that particular problem is *[Fix for "fatal: Authentication failed for"](https://stackoverflow.com/questions/69979522/)* (despite the unspecific title). – Peter Mortensen Nov 19 '21 at 23:52

5 Answers5

59

I believe I have found a solution to this problem. None of the solutions above worked for me. I think the root cause of this issue is that GitHub has ended support for password authentication on August 13, 2021. Instead a personal access token needs to be used.

The steps to solve this issue are as follows:

  1. Create a personal access token on GitHub.com. Tutorial here
  2. Go back to Visual Studio Code and open terminal. Type in the following command with your own user information:
git remote set-url origin https://<TOKEN>@github.com/<user_name or organization_name>/<repo_name>.git

In case you would like to follow a video guide, this one proved to be quite helpful.

Meena Chaudhary
  • 8,537
  • 12
  • 49
  • 81
aleksejjj
  • 995
  • 2
  • 13
  • 24
57

I solved it by following Caching your GitHub password in Git.

The steps are as follows:

  1. Download and install Git for Windows
  2. Run Git Bash, 'cd' to the repository directory and enter git config --global credential.helper wincred
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
joakim
  • 1,494
  • 1
  • 13
  • 23
2

I had the same issue with my Visual Studio Code on Linux cloning a Visual Studio Git repository.

It was Solved by setting up the Alternate Authentication Settings under security settings on {your-account}.visualstudio.com

Screenshot:

See the screenshot

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
ADM-IT
  • 3,017
  • 21
  • 21
2

It happened to me after GitHub changed its policy on 13 August 2021 to authenticate using a personal access token (PAT) instead of a password.

I did these steps for myself. I am on Lubuntu 20.04.

  1. Created .gitconfig in my home directory and added the following

    [user]
       name = {your github username}
       email = {your email}
    [credential]
       helper = store --file ~/.git-credentials
    
  2. Created .git-credentials in my home directory as you can see above and added the following

    https://{your github username}:{your github PAT}@github.com
    
  3. Final step: Restart your terminal and voilà! Try to commit/push/pull in an existing Visual Studio Code Git folder and everything will work as before.

Security Issue

Your personal access token (PAT) will be exposed as clear ASCII text and can be read if anyone has access to your user account.

Uday
  • 61
  • 5
  • 1
    Using Elementary OS Odin, your solution worked perfectly for VSCode integration, just restarted VSCode, and boom! Thanks! – Bus42 Nov 16 '21 at 03:17
  • Re *"public access token"*: Don't you mean "[***personal*** access token](https://en.wikipedia.org/wiki/Personal_access_token)"? – Peter Mortensen Nov 22 '21 at 02:47
-1

git remote set-url origin https://USUARIO:SENHA@bitbucket.org/URL.git

worked for me!

  • 3
    This has already been mentioned in the other answers. *When answering older questions that already have answers, please make sure you provide either a novel solution or a significantly better explanation than existing answers.* – Eric Aya Nov 19 '21 at 16:41