Using Git with TFS 2017 - Works in Visual studio b

2020-03-31 14:42发布

问题:

We recently made the switch to Team Foundation Server 2017 using Git for our projects. Our TFS works well enough if we use it through the web interface or through Visual Studio, but if we try to use a third party tool such as Sourcetree, Git Extensions, or even the command line, we get a fatal: Authentication failed for https://[path_to_repo]. SSH works fine, but we want to use HTTPS because SSH is not yet supported inside Visual Studio.

I have uninstalled git from my machine and followed the instructions provided at this link https://www.visualstudio.com/en-us/docs/git/share-your-code-in-git-cmdline, which pretty much just says install the latest version of git and make sure Enable Git Credential Manager is enabled (it is). I have noticed that with git uninstalled from my machine, git in Visual Studio still works which leads me to believe that it is using its own embedded version of git like Sourcetree does.

I have tried to disable all forms of authentication in IIS on our TFS website so that it only accepts Windows Authentication and the only provider is NTLM, and Extended Protection is turned off.

We would like to continue to use our third party git tools along side visual studio. Visual studio does add some nice functionality but there are still some operations that we prefer to do in other tools.

EDIT: I put the incorrect version in the title/post. We are using TFS 2017. I apologize, I am not sure why I made that mistake.

回答1:

The answer turned out to be a configuration error on the client side. For some reason, even though we checked the box to enable git credential manager during the git-install, the global variable credential.helper=wincred was not set in any of our configuration files. Setting that variable allowed git to prompt us and remember our credentials.

I am not sure if it is related, but the Git Credential Manager standalone installer also fails for us on our machines. It fails to copy any of the files over to our git installation directory (C:\Program Files\Git). I had to enable logging of the git credential manager in order to see that it was failing because it appeared that it was succeeding. I will open an issue with the git credential manager to see if they can resolve this.

EDIT: A bug has been opened in Git Credential Manager for Windows regarding the credential.helper property. Another issue regarding Git has come to light as well.

The property to use GCM is credential.helper=manager not wincred. However, manager did not work in Git v 2.11.0. NTLM authentication seems to be a known issue, at least on the GCM side of things, and it was recommended I try downgrading to Git version 2.10.1. Once I downgraded, I was able to set the aforementioned property to manager and it worked properly.



回答2:

I've tried to create a new local Git repo in VS, then use git command line to push it to an empty git team project in TFS 2015, no error occurred, you may compare your step with mine:



回答3:

wincred might be more robust with Git 2.15.x/2.16 (Q1 2018) with a MinGW update.

See commit 601e1e7, commit 3c90bda (30 Oct 2017) by Jakub Bereżański (``).
(Merged by Junio C Hamano -- gitster -- in commit 55b5d92, 09 Nov 2017)

wincred: handle empty username/password correctly

Empty (length 0) usernames and/or passwords, when saved in the Windows Credential Manager, come back as null when reading the credential.

One use case for such empty credentials is with NTLM authentication, where empty username and password instruct libcurl to authenticate using the credentials of the currently logged-on user (single sign-on).

When locating the relevant credentials, make empty username match null.
When outputting the credentials, handle nulls correctly.