[git] Visual Studio Code always asking for git credentials

I started using Visual Studio Code, and I was trying to save my test project into GitHub, but Visual Studio Code is always asking for my GitHub credentials.

I have installed in my PC GitHub Desktop and also Git, I already ran:

 git config --global credential.helper wincred

but still Visual Studio Code is asking for the credentials.

Any help?

here is my .gitconfig file located in the user profile folfer:

    [filter "lfs"]
    clean = git-lfs clean %f
    smudge = git-lfs smudge %f
    required = true
[user]
    name = ddieppa
[user]
    email = [email protected]
[credential]
    helper = wincred

Here is the popup windows asking for the credentials:

enter image description here

I enter my GitHub credentials in the popup, but still getting this error in the Git output window in Visual Studio Code:

remote: Anonymous access to ddieppa/LineOfBizApp.git denied.
fatal: Authentication failed for 'https://github.com/ddieppa/LineOfBizApp.git/'

This question is related to git visual-studio github visual-studio-code

The answer is


All I had to do was to run this command:

git config --global credential.helper wincred

Then I was prompted for password twice.

Next time it worked without prompting me for password.


This has been working for me:
1. Set credential hepler to store
$ git config --global credential.helper store
2. then verify if you want:
$ git config --global credential.helper store

Simple example when using git bash quoted from Here (works for current repo only, use --global for all repos)

$ git config credential.helper store
$ git push http://example.com/repo.git
Username: < type your username >
Password: < type your password >

[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]

Will work for VS Code too.

More detailed example and advanced usage here.

Note: Username & Passwords are not encrypted and stored in plain text format so use it on your personal computer only.


apart from adding the ssh config entries above

if windows

Set-Service ssh-agent -StartupType Automatic 

in powershell now the vs code should not prompt...


Use ssh instead of http/https.

You will need to set ssh keys on your local machine, upload them to your git server and replace the url form http:// to git:// and you will not need to use passwords anymore.

If you cant use ssh add this to your config:

[credential "https://example.com"]
    username = me

documents are here.


Using ssh key in github


Simply follow those steps and you will set up your ssh key in no time:

  • Generate a new ssh key (or skip this step if you already have a key)
    ssh-keygen -t rsa -C "your@email"

  • Once you have your key set in home/.ssh directory (or Users/<your user>.ssh under windows), open it and copy the content


How to add sh key to github account?

  • Login to github account
  • Click on the rancher on the top right (Settings)
    github account settigns
  • Click on the SSH keys
    ssh key section
  • Click on the Add ssh key
    Add ssh key
  • Paste your key and save

And you all set to go :-)


The following steps walk you through how to:

  1. Generate SSH keys (without passphrase**)
  2. Add the public key generated in step 1 to your Git repository
  3. Confirm the above steps have been completed successfully
  4. Make your first commit (without having to provide a username / password)

**Generating SSH keys without a passphrase is unwise if your work is particularly sensitive.

OS - Fedora 28 | Editor - VS Code v1.23.0 | Repository - Git

Generate SSH keys:

  • ssh-keygen -t rsa -C "[email protected]"
  • Enter file in which to save the key: Press Enter
  • Enter passphrase: Press Enter
  • Enter same passphrase again: Press Enter

After completing the above steps, the location of your public key is shown in the terminal window. If the currently logged in user is 'bob' the location of your public key would be /home/bob/.ssh/id_rsa.pub

Copy and import public key to GitHub:

  • cat /home/bob/.ssh/id_rsa.pub

  • Copy the whole public key that is now displayed in your terminal window to the clipboard

  • Go to https://github.com and sign in
  • Click the user icon in the top right corner of the screen and select Settings
  • Click SSH and GPG keys
  • Click New SSH key
  • Enter a title, paste the public key copied to the clipboard in the first bullet point, and click Add SSH key

Confirm the above steps:

  • ssh -T [email protected]

  • yes

  • Hi ! You've successfully authenticated, but GitHub does not provide shell access.

First commit / push without having to enter a username / password: - touch test.txt

  • git add test.txt

  • git commit - opens editor, enter a message and save the file. If vi is your editor, press i once the file opens, enter a message, press esc, and then enter :x to save changes.

  • git push

The only hiccup you may encounter is when you attempt to SSH to GitHub. This link will provide some assistance -

Happy hunting!


I had a similar problem in Visual Studio Code.

I solved by changing the remote url to https. (in file .git/config)

[remote "origin"]
    url = https://[email protected]/plesk-git/project.git

and also

git config --global credential.helper wincred

pulled again, windows credential popup came out, problems solved.


For windows 10 : go to control panel/Credential manager/ Windows Credential--> click on the git link, --> edit--> update to new password. That should work


for windows 10 press windows key type cred and you should see "Credential Manager" in Control Panel click to open and then remove the related cached credentials then try again, it will ask user id password key in the correct password and you'll be good.

Happened with me when I changed my network password


I managed to stop this by carrying out the following steps.

  1. Uninstall Git Desktop (Not sure this is necessary)
  2. Uninstall Credentials Manager cd "C:\Program Files\Git\mingw64\libexec\git-core" followed by git-credential-manager.exe uninstall
  3. Reset credentials helper to use wincred git config --global credential.helper wincred
  4. User VS Code to Push some changes and re-input credentials.

NOTE: I was using a Personal Access Token as my password.


Try installing "Git Credential Manager For Windows" (and following instructions for setting up the credential manager).

When required within an app using Git (e.g. VS Code) it will "magically" open the required dialog for Visual Studio Team Services credential input.


I usually run this simple command to change the git remote url from https to ssh

git remote set-url origin [email protected]:username/repo-name-here.git

Last updated: 05 March, 2019

After 98 upvotes, I think I need to give a true answer with the explanation.

Why does VS code ask for a password? Because VSCode runs the auto-fetch feature, while git server doesn't have any information to authorize your identity. It happens when:

  • Your git repo has https remote url. Yes! This kind of remote will absolutely ask you every time. No exceptions here! (You can do a temporary trick to cache the authorization as the solution below, but this is not recommended.)
  • Your git repo has ssl remote url, BUT you've not copied your ssh public key onto git server. Use ssh-keygen to generate your key and copy it to git server. Done! This solution also helps you never retype password on terminal again. See a good instruction by @Fnatical here for the answer.

The updated part at the end of this answer doesn't really help you at all. (It actually makes you stagnant in your workflow.) It only stops things happening in VSCode and moves these happenings to the terminal.

Sorry if this bad answer has affected you for a long, long time.

--

the original answer (bad)

I found the solution on VSCode document:

Tip: You should set up a credential helper to avoid getting asked for credentials every time VS Code talks to your Git remotes. If you don't do this, you may want to consider Disabling Autofetch in the ... menu to reduce the number of prompts you get.

So, turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.

In Terminal, enter the following:

git config --global credential.helper cache
# Set git to use the credential memory cache

To change the default password cache timeout, enter the following:

git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

UPDATE (If original answer doesn't work)

I installed VS Code and config same above, but as @ddieppa said, It didn't work for me too. So I tried to find an option in User Setting, and I saw "git.autofetch" = true, now set it's false! VS Code is no longer required to enter password repeatedly again!

In menu, click File / Preferences / User Setting And type these:

Place your settings in this file to overwrite the default settings

{
  "git.autofetch": false
}

Use an SSH key without a passphrase.

Maybe this is obvious to some (wasn't to me). It also doesn't solve the issue if you absolutely require a passphrase, but this was a decent compromise in my situation on Mac.


In general, you can use the built-in credential storage facilities:

git config --global credential.helper store

Or, if you're on Windows, you can use their credential system:

git config --global credential.helper wincred

Or, if you're on MacOS, you can use their credential system:

git config --global credential.helper osxkeychain

The first solution is optimal in most situations.


Following that article:

You may just set GIT_SSH env. var. to the Putty's plink.exe program. (Then use the pageant.exe as a auth. agent)


This is how I solved the issue on my computer:

  1. Open Visual Studio Code
  2. Go to File -> Preferences -> Settings
  3. Under User tab, expand Extensions and select Git

enter image description here

  1. Find Autofetch on the right pane and uncheck it

enter image description here


For me I had setup my remote repo with an SSH key but git could not find them because the HOMEDRIVE environment variable was automatically getting set to a network share due to my company's domain policy. Changing that environment variable in my shell prior to launching code . caused VSCode to inherit the correct environment variable and viola no more connection errors in the git output window.

Now I just have to figure out how to override the domain policy so HOMEDRIVE is always pointing to my local c:\users\marvhen directory which is the default location for the .ssh directory.


You should be able to set your credentials like this:

git remote set-url origin https://<USERNAME>:<PASSWORD>@bitbucket.org/path/to/repo.git

You can get the remote url like this:

git config --get remote.origin.url

You can refer this link for setup a Git Credential

You can run the following command to save your git credentials. You no need to enter username and password every git command run. (Its for Windows)

git config --global credential.helper wincred

For Mac / Linux click on this link for How to save Git credentials


I solved a similar problem in a simple way:

  1. Go To CMD or Terminal
  2. Type git pull origin master. Replace 'origin' with your Remote name
  3. It will ask for the credentials. Type it.

That's all. I Solved the problem


In case you are on Windows PC Then answer you are looking for!
Install Git for Windows

That's it!


After fighting with something like this for a little while, I think I came up with a good solution, especially when having multiple accounts across both GitHub and BitBucket. However for VSCode, it ultimately ended up as start it from a Git Bash terminal so that it inherited the environment variables from the bash session and it knew which ssh-agent to look at.

I realise this is an old post but I still really struggled to find one place to get the info I needed. Plus since 2017, ssh-agent got the ability to prompt you for a passphrase only when you try to access a repo.

I put my findings down here if anyone is interested:


Automatic Git authentication. From the v1.45 Release Notes:

GitHub authentication for GitHub Repositories

VS Code now has automatic GitHub authentication against GitHub repositories. You can now clone, pull, push to and from public and private repositories without configuring any credential manager in your system. Even Git commands invoked in the Integrated Terminal, for example git push, are now automatically authenticated against your GitHub account.

You can disable GitHub authentication with the git.githubAuthentication setting. You can also disable the terminal authentication integration with the git.terminalAuthentication setting.


Solve the issue by following steps.

Uninstalled softwares Vscode and git and reinstalled the same. Changed the git repository clone url from ssh to https.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to visual-studio

VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio? How to download Visual Studio Community Edition 2015 (not 2017) Cannot open include file: 'stdio.h' - Visual Studio Community 2017 - C++ Error How to fix the error "Windows SDK version 8.1" was not found? Visual Studio Code pylint: Unable to import 'protorpc' Open the terminal in visual studio? Is Visual Studio Community a 30 day trial? How can I run NUnit tests in Visual Studio 2017? Visual Studio 2017: Display method references

Examples related to github

Does the target directory for a git clone have to match the repo name? Issue in installing php7.2-mcrypt How can I switch to another branch in git? How to draw checkbox or tick mark in GitHub Markdown table? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to add empty spaces into MD markdown readme on GitHub? key_load_public: invalid format git - remote add origin vs remote set-url origin Cloning specific branch

Examples related to visual-studio-code

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined raised when starting react app Visual Studio Code PHP Intelephense Keep Showing Not Necessary Error Cannot edit in read-only editor VS Code How to setup virtual environment for Python in VS Code? Pylint "unresolved import" error in Visual Studio Code Why do I keep getting Delete 'cr' [prettier/prettier]? How to set up devices for VS Code for a Flutter emulator VSCode single to double quote automatic replace js 'types' can only be used in a .ts file - Visual Studio Code using @ts-check How can I clear the terminal in Visual Studio Code?