我开始使用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凭据管理器。

其他回答

我在Visual Studio Code中遇到了类似的问题。

我通过将远程URL更改为https(在文件.git/config中)解决了这个问题:

[remote "origin"]
    url = https://user@server.com/plesk-git/project.git

还有:

git config --global credential.helper wincred

我又拉了一次,弹出了Windows凭据,问题解决了。

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

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

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

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

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

自动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.

打开Visual Studio Code的用户必须与执行Git命令的用户相同。然后在终端中执行如下命令。

git config --global credential.helper store
git pull

在下一个操作push或pull中,您将不会看到它请求Git凭据。

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

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

git config --global credential.helper wincred

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