48

I'm using Visual Studio, and the GitHub Extension. I am able to sign in, then clone my team's repository, and then pull changes successfully.

When it comes time to push my changes back to remote, I get a blank command prompt appear on the screen briefly, and then the following errors in the output window:

Error encountered while pushing to the remote repository: Git failed with a fatal error.

fatal: AggregateException encountered. One or more errors occurred.

error: cannot spawn askpass: No such file or directory

fatal: could not read Username for 'https://github.com': terminal prompts disabled

EDIT: pushing via the command line works, as does pushing via the GitHub desktop application, just not within this extension.

Any ideas why this might be happening? I can't see why it needs the Username given that I have signed into the extension.

Dietrich Epp
  • 205,541
  • 37
  • 345
  • 415
Matt
  • 1,412
  • 3
  • 15
  • 18
  • 2
    Do you use a password extension? It might be blocking the User Access Control. You could also revise your remote url to include your username. http://stackoverflow.com/questions/6565357/git-push-requires-username-and-password – Taylor Ackley Mar 20 '17 at 23:29
  • 2
    @TaylorAckley thanks, I thought I tried everything in the other questions but didn't see this one hiding away. Adding the username to the remote url was the only thing that worked (I have no password extension or anything unusual like that). If you add it as an answer I'll accept it. – Matt Mar 21 '17 at 01:37
  • 1
    I was able to solve this by getting a 'access token' credential (that works between Visual Studio and Azure-Devops) and re-booting the computer hosting Visual Studio. I don't know if this is a general solution or not. – JosephDoggie Nov 18 '19 at 19:47

10 Answers10

34

As per my comment. You can include your username in the remote URL (similar to FTP).

Example without password (SSH):

git remote set-url origin git@github.com/username/repo.git

Example with password (https)

https://name:password@github.com/username/repo.git

Source: Git push requires username and password

Updated 5/14/2018 to correct github.org to github.com in the original answer

Super Jade
  • 5,609
  • 7
  • 39
  • 61
Taylor Ackley
  • 1,397
  • 1
  • 16
  • 31
  • 1
    Actually, git remote set-url origin https://username:password@github.com/username/repo.git but thanks anyway. Save me from the sysadmin. – Stefan Steiger Feb 26 '18 at 09:25
  • 3
    In addition, when putting your password into the repo url, you need to replace special characters with their corresponding URL encoded values, for example: myp@ssword --> myp%40ssword – maximus Mar 03 '19 at 00:01
  • @Morgs see the above comment from maximus. – Taylor Ackley Nov 17 '20 at 00:58
  • Where would you set this in visual studio? It seems to spawn a new terminal which doesn't know about this setting. – kev Jun 27 '22 at 10:40
  • @kev - my answer is accepted, but there are better (newer) answers. – Taylor Ackley Jul 08 '22 at 18:50
11

Check that Windows does not have a pending update. If it does, update and restart.

Scott
  • 526
  • 6
  • 10
  • 6
    This was it for me. Updating Visual Studio was required before it would allow me to do a push. – Jay S Sep 20 '18 at 20:49
11

This worked for me:

Deleting the file %localAppData%\GitCredentialManager\tenant.cache and then re-trying your logon.

Anthony
  • 193
  • 1
  • 13
3

In windows go to credentials manager and check if generic credentials list has the below entries

git:https://github.com

https://github.com

If these entries are not present add these entries with username and password and it should work.

user2713706
  • 147
  • 6
3

This happened to me when syncing. Updating visual studio to the latest version did it for me.

Squibly
  • 335
  • 2
  • 7
2

Using Windows Credential manager

**Windows Credential manager**

After seeting username, password in Windows Credential Manager, set git config to read from credential manager. Open gitbash, run command:
git config --global --add credential.helper manager

Palash Roy
  • 1,547
  • 1
  • 15
  • 11
1

What worked for me was to disconnect from all the existing connections in Visual Studio, remove them one-by-one and connect from scratch. Then immediatelly I was able to clone the repository again.

Neeraj Kumar
  • 771
  • 2
  • 16
  • 37
Tadeáš Bucha
  • 362
  • 3
  • 15
1

I faced the same issue after I have only TLS1.2 enabled on my PC. After enabling TLS 1.1, SSL.x the issue was resolved. For enabling and disabling I used IISCrypto software. Hope that helps the team and other users.

vCillusion
  • 1,749
  • 20
  • 33
1

In my case the same issue coming on below scenario:

We are under corporate network. So we have our own proxy. When we try cloning we cant able to download due to same error.

I added proxy url in our git config.

[http]
 proxy=http://YourNameHere:YourPasswordHere@proxy.aaa.com:6050/
 sslVerify = false

[https] 
proxy=http://YourNameHere:YourPasswordHere@proxy.aaa.com:6050/
 sslVerify = false

Issue disappears and i can do all git operations.

Andi AR
  • 2,678
  • 2
  • 23
  • 28
  • 2
    For other people reading this, be wary of sslVerify - false it poses a security risk and opens you to man-in-the-middle attacks. This might be a valid solution for Andi, but not for everyone so please be wary. A more robust solution to corporate environments is adding the certificate of the proxy to the trusted root certificates (a separate discussion). – Alex KeySmith Oct 09 '18 at 12:13
0

I have updated my Visual studio 2017 and restarted it. Now it's working fine.My updated Visual studio version:

Binu
  • 1