TFS(Visual Studio Team Services) / Azure Devops git认证失败 authentication fails 的解决方案 http协议

问题描述

TFS 的git仓储地址使用http协议时,在visual studio中使用正常,可是git pull运行失败,提示 authentication fails。
初步判断原因为默认的 credential.helper 与 TFS 不兼容导致。
TFS 2015 与 Azure Devops(TFS 2019)都有这个问题。TFS2019建议使用ssh认证方式绕过这个问题,这样也更加安全。

解决方法

使用管理员身份运行 git-bash / cmd / powershell 执行以下指令

git config --system credential.helper wincred

再次执行git pull,依照提示输入正确的账号密码即可。

管理凭证可打开:windows控制面板-用户账户-凭据管理器-Windows凭据-普通凭据。如果存储的凭据有误,可修改或删除错误的凭据。

进阶配置详解

有关credential helper for windows的详细内容:https://github.com/Microsoft/Git-Credential-Manager-for-Windows
git使用credential.helper来存储凭证。默认为manager(system级别)。在安装git时,会默认安装 credential.helper。

查看系统支持的credential.helper

git help -a | grep credential-

查看已保存的相关设置

git config --global -l | grep credential.helper
git config --system -l | grep credential.helper

去除credential.helper 设置,system级别需要管理员权限,system级别的配置会覆盖global级别的设置。

git config --system --unset credential.helper 
git config --global --unset credential.helper 

清除保存的凭证 https://stackoverflow.com/questions/15381198/remove-credentials-from-git

git credential-manager clear

Linux系统环境,可设置credential.helper为store

使用store会将密码明文存储,查看或修改已存储的密码可编辑配置文件 ~\.git-credentials

原文地址:https://www.cnblogs.com/wswind/p/9828805.html