Git failed with a > fatal error. could not read Username for

57,750

Solution 1

It’s mainly caused by the credentials have been remembered by Credential Manager. You should remove the credentials for xxx.visualstudio.com which have been stored in Credential Manager.

Such as if the pc’s OS is windows, you can open Credential Manager -> Windows Credentials -> under Generic Credentials -> remove the credentials like git:https://xxx.visualstudio.com.

enter image description here

Then clone again, git will let you input the credential for the repo. After inputing the username(email address) and password which can access the VSTS account, the repo should be cloned successful.

Solution 2

I did not have any git credentials registered with Windows Credentials and I still received this error, even after selecting my windows user account in the VS User Dialog popup.

After a day of trying different things like re-installing GIT for windows, I managed to fix this issue by deleting a this file: "C:\Users(profile)\AppData\Local\GitCredentialManager\tenant.cache".

On the next retry, a GIT entry showed up in my Windows Credentials generic list. See Issue

Solution 3

Simply update your Visual Studio to the latest version. This bug was reported and fixed with the latest updates. Worked for me.

Solution 4

I had a similar problem.

Push from within VS2017 would fail, I was getting an error spawning git-askpass.exe

I fixed it by copying/replacing all the files in the VS2017 git-core folder with the files from the git-core folder created by the Git installation.

I might have only needed the new git-credential-manager.exe, but I replaced everything.

So far, no problems.

VS2017 folder: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\mingw32\libexec\git-core

Git installation folder: C:\Program Files\Git\mingw64\libexec\git-core

Solution 5

Okay after much heartache I managed to resolve the issue (at this point had I tried everything including deleting accounts from Credential Manager).

I started up Visual Studio 2017 and then I opened my repository and next went to the Team Explorer tab for the repository.

I left-clicked on the Sync option and then again on the sync link button to initiate the pull/push actions. This caused Visual Studio to display a dialog box asking me to select my credentials.

However what I did to resolve the issue was to first "Forget" the account that I was trying to use in the first place (left-click on the 3 dot icon on the right) and then I was prompted for the username and password again - enter the correct one's and it should all sync up nicely now!

Share:
57,750

Related videos on Youtube

danbord
Author by

danbord

Freelance Programmer .NET C# Angular Azure Firebase XAML

Updated on July 09, 2022

Comments

  • danbord
    danbord almost 2 years

    I've been struggling with that issue for a couple days now.

    I'm unable to connect to my Git project (stored in VisualStudio.com) from a specific computer (it works on my second PC). Whenever I try to Sync or Clone my repository, VS2017 asks for my user credentials (twice) and the I get the following error :

    Error: cannot spawn askpass: No such file or directory Error encountered while cloning the remote repository: Git failed with a fatal error. could not read Username for 'https://.visualstudio.com': terminal prompts disabled

    Can't remember if I changed anything that could've caused that...

    • sr28
      sr28 about 6 years
      Just had this issue. In my case I was able to access it fine yesterday but not today. I modified my .gitconfig to use SSH, then got prompted, closed it without connecting, set my .gitconfig back to how it was and retried. It then worked again.
  • Anuranjan Srivastav
    Anuranjan Srivastav about 6 years
    I followed the steps but it did not work for me.I am using VS2017 and trying to connect to VSTS git project. I getting below error Error encountered while pushing to the remote repository: Git failed with a fatal error. Win32Exception encountered. Failed to write credentials cannot spawn askpass: No such file or directory could not read Username for 'xxxxxx.visualstudio.com': terminal prompts disabled Pushing to xxxxxx.visualstudio.com/_git/StockTrace
  • Stefan Steiger
    Stefan Steiger about 6 years
    And should that not be possible because you have no admin rights; git remote set-url origin username:[email protected]/username/repo.git - that worked for me. Note: Will store your github password in plaintext in ./git/config
  • iroel
    iroel about 6 years
    It doesn't work for me when building in TFS. Suppose the submodule is configured using FQDN (i.e. subdomain.domain.com/tfs/DefaultCollection/Project/_git/…). When TFS build cloning the git repository, it uses subdomain only (subdomain/tfs/DefaultCollection/Project/_git/Repository1). I have no idea why it uses subdomain only during cloning. FYI, I configured TFS server the public url to use FQDN. I've tried to clear generic credential many times and still no luck. I can also reproduce the issue by using the same way.
  • iroel
    iroel about 6 years
    Just tried again, the TFS build succeeded when it uses the same URL. In this case, I use subdomain only just like TFS build uses.
  • J. Horn
    J. Horn almost 6 years
    I changed my password with VS open -- won't do that again -- and Git failed with an authentication error. I removed my 2 git:... credentials, in Credential Manager and VS prompted for a username/password when syncing. Problem solved.
  • MikeZ
    MikeZ over 5 years
    I tried this, it did not work for me. I had to get the latest git-credential-manager.exe and put it in the VS2017 git-core folder .
  • Matstar
    Matstar over 5 years
    I updated the credential manager, and it did not resolve my issue, but glad to see it worked out for you.
  • user2847376
    user2847376 over 5 years
    I have the latest version of VS and this is still happening for me.
  • zgue
    zgue over 5 years
    Today we connected our DevOps account to our AAD. After that we could not longer clone our repos. Your answer was the solution for this issue. Thanks a lot.
  • Mike Gledhill
    Mike Gledhill over 5 years
    I'm using a version of VS2017 updated 9 months after you made this suggestion... and the problem is still there.
  • Ricardo Zambon
    Ricardo Zambon over 5 years
    This worked for me, I was having this same issue with VS 2017 Community 15.8.1. Thanks a lot!
  • purplesoft
    purplesoft about 5 years
    delete all git stored credentials from credential manager and delete tenant.cache file work for me. thanks!
  • BobbyTables
    BobbyTables over 4 years
    This in combination with the @Matstar answer solved it. Needed to do both (remove tenant.cache +remove credentials in manager)
  • solujic
    solujic over 4 years
    seems like a VS issue, I tried in VS2017 didn't work, I saw this and said hey let me try on VS2019 since I also have it installed and it worked (might be useful for someone).
  • Preet
    Preet over 4 years
    Worked for me as well. Thank you! replacing only the git-credential-manager.exe didn't worked.
  • Gruss
    Gruss about 4 years
    In addition to this I had to run Visual Studio as an Administrator for the first time for the repo to sync correctly.
  • Stephen Pham
    Stephen Pham almost 4 years
    Along the same line, removing the credential for "git:github.com" helped fix the error "fatal: could not read Username for 'github.com': terminal prompts disabled" that I encountered in a Azure DevOps pipeline.