143

I am trying to use git to push my repository to a visual studio team services project, but I get the error:

fatal: Authentication failed for (url of team project)

I am using the commands:

git remote add origin
     https://XXXXXXX.visualstudio.com/DefaultCollection/_git/project

git push -u origin -–all

Any idea of the fix for this?

Sampath
  • 63,341
  • 64
  • 307
  • 441
GurdeepS
  • 65,107
  • 109
  • 251
  • 387

25 Answers25

256

I had a same issue recently (visual studio 2017 & Windows 10), and solved it using the following method:

Control Panel --> Credential Manager --> Manage Windows Credentials --> Choose the entry of the git repository, and Edit the user and password.

Done.

kxiaocai
  • 2,803
  • 1
  • 12
  • 8
  • 5
    I used this method when my Personal Access Token expired. Go to <>/_usersSettings/tokens to create a new one and then set it as the password in Credential Manager. – Even Mien May 24 '19 at 17:23
  • God.... thank you. This is the only solution that worked for me. – Dominik Sajovic Nov 03 '20 at 16:27
  • Depending on what version of VS you have, you can go to terminal and type git push and it'll give you option which way to authenticate for git enterprise, I chose 'wincred' and it took it. You need to set the Git Enterprise url in settings first. – Smart Coder Mar 02 '23 at 20:17
38

If you wish to use GIT CLI and not interact with the build in GIT wrappers in Visual Studio you need to enable Alternate Authentication Credentials

How?

Open your account (VS Online account) 
-> click on your name on the top right 
-> My Profile
-> Credentials.

and set it up.


enter image description here

enter image description here

Community
  • 1
  • 1
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
37

I have faced the same issue. The error output window looks like this: authentication failed Image

Following the steps resolved the issue:

  1. Go to Control Panel --> Credential Manager --> Windows Credentials
  2. Below Generic Credential, choose an entry of the git & update password.

    solution window

  3. Password should be same as windows(system) login password.

Adrian W
  • 4,563
  • 11
  • 38
  • 52
Anusha M Shetty
  • 379
  • 3
  • 4
  • on giving my machine password didn't worked, i generated personal access token (PAT) from VSO and used it. then in VS2019 am able to pull latest. – Pavan N Sep 03 '21 at 08:04
18

The best option today is to install https://github.com/Microsoft/Git-Credential-Manager-for-Windows that supports VSO, GitHub and is improving every month.

Giulio Vian
  • 8,248
  • 2
  • 33
  • 41
  • 2
    @dotnetdev Please accept this answer 'cause this is a recommended way of resolving the issue. – Deilan May 17 '17 at 07:14
  • 1
    This is also available for Mac and Linux at https://github.com/Microsoft/Git-Credential-Manager-for-Mac-and-Linux - worked perfectly for me without having to add less-secure "alternative credentials". – Breeno Oct 31 '17 at 13:02
  • 1
    This is indeed the "de facto" solution that microsoft provided. Other solutions that indeed work here shall be considered as tweaks. – Stephane Oct 13 '18 at 20:08
15

With VSTS the url is, When you copy git clone url from vsts you always get

https://orgname@dev.azure.com/org/project/_git/repo

Replace orgname@ with your alternate username that you would have created in VSTS -> profile -> Security.

final git url -

https://alternateusername@dev.azure.com/org/project/_git/repo

Max
  • 589
  • 5
  • 6
  • I have multiple logged in credentials -- this was the easiest and most direct way to ensure that it uses the correct cached credential. – bryanbcook Dec 18 '20 at 23:35
12

I had the same problem, I tried to update my password using windows credential manager, it still didn't fix the issue

Control Panel --> Credential Manager --> Manage Windows Credentials --> Choose the entry of the git repository, and Edit the user and password.

I then deleted all the git related entry in credentials manager and then tried to use Git using visual studio, this time it prompted for new credentials

7

For Linux users who can't use Microsoft Credential Manager. This is the only solution I found aside from using ssh. You need to generate the credentials in the repository view (See images below) get git credentials

And the result is: get Git credentials result

Copy the password!. Azure devops doesn't store it and you won't be able to see it again!

NB: As of 2020 Alternate credentials have been disabled check Microsoft blog

Melchia
  • 22,578
  • 22
  • 103
  • 117
6

Delete '.git/config' and try again. Attention this will may reset some git settings too!

I've tried alternative credentials and Personal Access Token for many times with right credential and it kept telling me "fatal: Authentication failed".

Finally, I found there is a file named ".git/config" located at the root of my Repo. I deleted this file and type in my credentials again, it worked.

Bruno Bieri
  • 9,724
  • 11
  • 63
  • 92
Longfei Wu
  • 815
  • 10
  • 9
5

Control Panel --> Credential Manager --> Manage Windows Credentials --> Choose the entry of the git repository, and Edit the user and password. Delete '. git/config' and try again. Attention this will may reset some git settings too!

Namitha
  • 81
  • 1
  • 7
3

I suddenly started receiving this error when attempting to push changes from VS2017 to a VSTS Git repository. This functionality had worked the day before.

I checked my git.log file and saw a different exception :-

19:43:57.116665 ...zureAuthority.cs:184 trace: [ValidateCredentials] server returned: 'Unable to connect to the remote server.

I downloaded the latest Git CredentialManager source from Gits Credential Manager repo and debugged it.

Once authenticated, the following exception occurred :-

No connection could be made because the target machine actively refused it 127.0.0.1:8888

I then realised that I had recently setup Fiddler to act as a proxy for all services as per the article capturing-traffic-from-.net-services-with-fiddler

Once I ran Fiddler, I was able to successfully connect.

Mr Slim
  • 1,458
  • 3
  • 17
  • 28
3

My solution was a little bit different and faster :)

  1. Go to Windows Credentials (Start-> Windows Credentials) and remove credentials for your repository (they starts with git:xxx)
  2. Go to VSCode and in Terminal write:

    config credential.helper wincred

  3. Go to Visual Studio (no VSCode) and make a git pull. A popup will show asking for credentials. Put your credentials for the repo

  4. Go to VSCode and make a git pull. Credentials were automatically fetched from wincred store

Credentials are automatically created and stored in wincredentials, so the next time you cannot be asked for credentials. (also a Personal Access Token will be provided from visualstudio.com if you are using DevOps hosted git repo).

3

Go to Windows Credentials Manager and update the credentials for GIT.

2

I had this problem and the instructions from a tech at Microsoft fixed it for me:

  • Close all instances of Visual Studio.
  • Open the Task Manager and check if any TFS Services are running. Select each of them and click on End Process Tree.
  • Browse to the folder below and delete all the contents and folders in %LocalAppData%\Microsoft\Team Foundation{version}\Cache
  • Go to Control Panel -> User Accounts -> Manage your Credential -> Windows Credential, select the VSTS URL to remove it
  • Then go to "C:\Users\USER NAME\AppData\Local\GitCredentialManager\tenant.cache" and delete it
  • Also go to "C:\Users\USER NAME\AppData\Local.IdentityService" and delete it
Casey
  • 81
  • 4
2

Deleting the token from the Windows Credential Manager worked. Visual studio asked to reenter the credenial.

  1. Go to Control Panel>Credential Manager
  2. Locate the git credential
  3. Click the down arrow to expand the credential and hit "Remove"
  4. Reopen Visual Studio. Go to Team Explorer and "Connect". It will ask for you to re-enter your credential
syspotato
  • 21
  • 1
1

I've tried lots of options, but the one that worked for me was to:

  1. Download the Git Password Manager from its Releases section

  2. Try to do simple git fetch which will automatically bring the window(alternate to default windows one for example) and ask to enter username and password but with more elegant way than the standard one.

After correctly entering the credentials it worked, though I was getting an error before.

P.S. If you are getting "Wrong Credentials" kind of errors always check if the repository username and password are correct. If you hesitate just reset the password and try to use the same one in the Git Password manager window.

Arsen Khachaturyan
  • 7,904
  • 4
  • 42
  • 42
1

2 to 5 minutes to setup!

  • Create your SSH keys (~/.ssh/)

ssh-keygen -C "jamal@fabrikam.com"

  • Add the public key to Azure DevOps Services/TFS
  • Clone the Git repository with SSH

Source

jnermano
  • 51
  • 5
1

I was using Azure Personal Access Token, so my steps to resolve it were:

  1. Create a new one (PAT) and copy the password generated.
  2. Go to Control Panel -> Windows Credential Manager
  3. Search for those git url: git:https://dev.azure.com/{site} and git:https://{site}@dev.azure.com/{site} (both url could be different in your case, but they should start with "git:")
  4. In both credentials, edit user as "PersonalAccessToken" and paste the password of the PAT that you'd generated before.

That resolved my issue.

Hope this helps someone!

EricSchaefer
  • 25,272
  • 21
  • 67
  • 103
Vicnroll
  • 64
  • 6
1

For me, this happened out of nowhere. Turns out my token expired without me noticing. Just had to go to settings -> Personal Access Tokens -> On the drop-down select expired -> Regenerate -> Grab the new token and store it -> When VS Code asked for pass used it and voila, problem solved. Hopefully this help someone, took me a few minutes to figure out.

José Ripoll
  • 504
  • 1
  • 7
  • 17
0

All i needed were the correct credentials. while deploying to a web app, i had to go to Deployment Center, Deployment Credentials. And then use either the App Credentials or create User Credentials. After this, delete the cached credentials on the local machine (windows: Control Panel\User Accounts\Credential Manager). run "git push webapp master:master" again, enter either of the Deployment Credentials. This worked for me.

mahesh
  • 237
  • 2
  • 8
0

In the case you are on something else then windows and your boss is forcing you to use azure devops, and you don't want to use SSH, and you want to use to plain old way, do the following.

You have to enable 'Alternate credentials' (I know it's annoying) or you need to create an access token. Creating an access token in this case is more like a temporary random password. If you use the windows tooling it is done for you.

Any way, go to Security in the profile context menu in the right upper corner.

Security settings

Then if your boss/manager/dude that has the admin rights is favoring you the 'Alternate credentials' are enabled. Otherwise accept your fate and generate a 'Personal access token'.

Security settings

botenvouwer
  • 4,334
  • 9
  • 46
  • 75
0

After struggling with git authentication and azure devops server and trying other answers this tip here worked for me.

Using Visual Studio? Team Explorer handles authentication with Azure Repos for you.

Once I connected to the repo using Team Explorer I could use command line to execute git commands.

VahidNaderi
  • 2,448
  • 1
  • 23
  • 35
0

If you are entering your credentials into the Visual Studio popup you might see an error that says "Login was not successful". However, this might not be true. Studio will open a browser window saying that it was in fact successful. There is then a dance between the browser and Studio where you need to accept / allow the authentication at certain points.

AdamCodes716
  • 155
  • 2
  • 11
0

Removing git origin and adding again helped me.

Looking at the origin url I found that url contained some hash value (it looked like some auth value). Therefore, removing origin and adding again fixed the problem.

osynavets
  • 1,199
  • 1
  • 12
  • 22
0

09-02-2022

Windows 10 Pro PC

My issue was the outdated Git for Windows package. So I got the latest version from here and no issues now.

Sampath
  • 63,341
  • 64
  • 307
  • 441
0

Today I was also facing a "fatal: Authentication failed for [REPO-URL]" when trying to push updates from my local repo to the remote Azure DevOps repo. Since for the initial clone of the remote repository I had used a personal access token generated in the Azure DevOps website (git clone -b [BRANCH-NAME] https://[USERNAME]:[TOKEN]@dev.azure.com/[ORG]/[PROJECT]/_git/[REPO]) and since it had expired, I first generated a new access token from the ADO website, I then opened the local "config" file inside the local .git folder and in it I updated the token in the url to the remote repository. I re-executed my push and everything worked as expected.

whatever
  • 2,492
  • 6
  • 30
  • 42