76

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.

6
  • try to commit from command line and see if it works or not. If it does, then your VSCode settings might have issues.
    – user2185573
    Commented Sep 17, 2015 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
    Commented Sep 17, 2015 at 21:04
  • Download a client like Git Bash first. Use that as a replacement. Check out the git bash column in git-for-windows.github.io. This would allow you to run this command : git push origin master
    – user2185573
    Commented Sep 17, 2015 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
    Commented Sep 17, 2015 at 23:00
  • 1
    Same here. Credentials work with command line, but not with VS Code.
    – Prabhu
    Commented Dec 3, 2015 at 16:34

9 Answers 9

90

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.

7
  • 1
    Thx, this solution solved the issue!
    – Valentoni
    Commented Nov 16, 2021 at 21:07
  • 1
    This should be the accepted answer since it is not Windows specific. Commented Nov 17, 2021 at 15:10
  • The video helps if just the command is not cutting it for you
    – Martijn
    Commented Nov 18, 2021 at 12:12
  • doesn't seems working Commented Nov 20, 2021 at 18:25
  • git remote set-url origin https://<user_name>@github.com/<repo_name>.git and windows credential manager should ask for your password, provide your token for the password.
    – ok4
    Commented Jan 21, 2022 at 12:00
65

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
3
  • 3
    Fixed my issue with not being able to commit to private repo.
    – Rasmus-E
    Commented Oct 26, 2015 at 8:50
  • I tried this but it didn't work. Any other means of getting it to work?
    – aleksejjj
    Commented Oct 15, 2021 at 18:58
  • Didn't work for me. Commented Nov 15, 2021 at 22:19
7

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.

4
  • 1
    Using Elementary OS Odin, your solution worked perfectly for VSCode integration, just restarted VSCode, and boom! Thanks!
    – Bus42
    Commented Nov 16, 2021 at 3:17
  • Re "public access token": Don't you mean "personal access token"? Commented Nov 22, 2021 at 2:47
  • Worked perfect on Ubuntu 22.04, many thanks dude!
    – NenchoDM
    Commented Aug 28, 2022 at 8:23
  • Worked for me as well on Pop!_OS v22.04. Thanks. Commented Aug 31, 2023 at 19:21
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

2

Git stopped using account password for code push, instead generate 'personal access token' from git account and use the same as password for code push. It absolutely worked for me to resolve this error.

Note : Git doesn't store 'personal access token', so copy it in your file/machine for future/multiple use.

0

git remote set-url origin https://USUARIO:[email protected]/URL.git

worked for me!

1
  • 4
    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
    Commented Nov 19, 2021 at 16:41
0

Configure VS Code Github authentication using Github CLI, gh.

  1. Download and install gh here
  2. After installation, open vs code terminal and login to github with gh auth login
  3. You'll be prompted to choose an authentication method. Available authentication methods are password and personal access token. I'd recommend using a personal access token because your authentication details will be stored in plain text on your local machine. Here is a tutorial on creating a personal access token. You can then generate a personal access token here. Ensure your personal access token have the minimum required scopes repo, read:org, workflow
  4. Paste your personal access token and gh will handle the rest.

If you've gone through the above steps before but your personal access token has expired, you can simply generate another personal access token and paste inside the /home/<user>/.config/gh/hosts.yml file. Note that this file path is for linux/MAC users. Windows users should be able to locate similar path in their filesystem.

0

In case of using VSCode git graph's buttons that result in message error like this: Unauthorized fatal: Authentication failed ... unable to fetch from remote(s)

This worked for me:

  1. git remote set-url origin "<the git you want to clone/pull/fetch>.git"
  2. Enter your email & password in VSCode pop-ups
  3. Now you can use git graph or cmd normally again
-1

I faced a similar problem. I was coding in vs code. So, I just tried another terminal to push my code and it works for me!!

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Dec 2, 2022 at 13:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.