我开始使用Visual Studio Code,我试图将我的测试项目保存到GitHub,但Visual Studio Code总是要求我的GitHub凭据。

我已经在我的PC上安装了GitHub Desktop和Git。我已经跑了:

 git config --global credential.helper wincred

但是Visual Studio Code仍然在要求凭证。

我该如何解决这个问题?

下面是我的.gitconfig文件,位于用户配置文件文件夹中:

    [filter "lfs"]
    clean = git-lfs clean %f
    smudge = git-lfs smudge %f
    required = true
[user]
    name = ddieppa
[user]
    email = fake@live.com
[credential]
    helper = wincred

下面是弹出窗口要求凭据:

我在弹出窗口中输入了我的GitHub凭证,但仍然在Visual Studio Code中的Git输出窗口中得到这个错误:

remote: Anonymous access to ddieppa/LineOfBizApp.git denied.
fatal: Authentication failed for 'https://github.com/ddieppa/LineOfBizApp.git/'

当前回答

您可以参考此链接来设置Git凭据。

您可以运行以下命令来保存Git凭据。你不需要每次运行Git命令时都输入用户名和密码(适用于Windows):

git config --global credential.helper wincred

对于Mac / Linux,如何保存Git凭据,请参见Mac和Linux的Git凭据管理器。

其他回答

自动Git认证。v1.45版本说明:

GitHub authentication for GitHub Repositories VS Code now has automatic GitHub authentication against GitHub repositories. You can now clone, pull, push to and from public and private repositories without configuring any credential manager in your system. Even Git commands invoked in the Integrated Terminal, for example git push, are now automatically authenticated against your GitHub account. You can disable GitHub authentication with the git.githubAuthentication setting. You can also disable the terminal authentication integration with the git.terminalAuthentication setting.

下面这篇文章:

您可以将GIT_SSH环境变量设置为PuTTY的plink.exe程序。

(然后使用pageant.exe程序作为身份验证代理。)

(这个答案不是特定于GitHub,而是我使用BitBucket,但它也可以在GitHub中工作,因为概念是相同的)

就我而言,我使用的是Bitbucket应用程序密码,它总是要求我进行身份验证。

停止自动读取并不能解决问题,因为我一天要拉和推好几次,每次输入应用程序密码都很糟糕。

此外,我需要将应用程序密码存储在不安全的地方,这也是我不想使用凭证的原因。助手存储,它以明文存储密码,而不是使用凭据。助手wincred,它是加密的。

当对话框提示我使用浏览器而不是应用程序密码时,我要求使用浏览器登录,这是可行的,原因超出了我的理解。现在它不再要求凭据了(我不得不暂时改变我的默认浏览器,因为我工作时使用的bitbucket帐户不在我的默认浏览器中,对话框尝试使用默认浏览器进行身份验证)。

在与这样的事情斗争了一段时间后,我想我想出了一个很好的解决方案,尤其是在GitHub和Bitbucket上有多个账户的时候。然而,对于Visual Studio Code,它最终从Git Bash终端启动,这样它从Bash会话继承了环境变量,并且它知道要查看哪个ssh-agent。

我仍然很难找到一个地方来获取我需要的信息。另外,自2017年以来,ssh-agent只有在您尝试访问存储库时才会提示您输入密码短语。

我把我的发现写在这里,如果有人感兴趣的话。

我们需要配置VS Code以在Git命令之上提供身份验证。

下面我将展示如何设置扩展设置。