我开始使用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/'

当前回答

相反的问题,但相关的:

在我的情况下,我努力与Visual Studio Code集成终端不忘记输入的密码,即使缓存助手超时已经过期。

不过,外部终端会话工作正常。

我发现在Visual Studio Code中有一个选项,它允许你在实际的Git插件上设置一个可选的缓存,这并不允许预期的行为发生。

一旦检查,我的密码在缓存超时时就被忘记了,所以我可以毫不费力地从个人账户跳到工作账户:)

Linux和Visual Studio Code 1.58.2。

其他回答

尝试安装“Git凭证管理器For Windows”(并按照说明设置凭证管理器)。

当在应用程序中使用Git(例如Visual Studio Code)时,它将“神奇地”打开所需的对话框,用于Visual Studio Team Services凭据输入。

如果你是在Windows电脑上,那么安装Git for Windows。就是这样!

Windows 10操作系统:进入控制面板→凭证管理器→Windows凭证→点击Git链接→编辑→更新新密码。这应该有用。

这对我很有用。你只需要输入一次PAT。 Git配置——全局凭据。辅助wincred

这对我来说很管用:

设置凭证帮助存储: Git配置——全局凭据。辅助存储 然后验证你是否想: Git配置——全局凭据。辅助存储

这里引用了一个使用Git Bash的简单示例(仅适用于当前存储库,对所有存储库使用——global):

git config credential.helper store
git push http://example.com/repo.git

Username: < type your username >
Password: < type your password >

[several days later]

git push http://example.com/repo.git

[your credentials are used automatically]

它也适用于Visual Studio Code。

这里有一个更详细的示例和高级用法。

注意:用户名和密码不加密,以纯文本格式存储,因此仅在您的个人计算机上使用。