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

当前回答

我用简单的方法解决了一个类似的问题:

进入CMD或终端 输入git拉origin master。将“origin”替换为远程名称 它会要求提供证书。类型。

这是所有。我解决了这个问题。

其他回答

下面是我在电脑上解决这个问题的方法:

开放Visual Studio代码 进入菜单文件→首选项→设置 在User选项卡下,展开Extensions并选择Git 在右侧窗格中找到Autofetch并取消选中它

为什么Visual Studio Code需要密码?因为Visual Studio Code运行自动获取功能,而Git服务器没有任何信息来授权您的身份。它发生在:

Your Git repository has a https remote URL. Yes! This kind of remote will absolutely ask you every time. No exceptions here! (You can do a temporary trick to cache the authorization as the solution below, but this is not recommended.) Your Git repository has ssh remote URL, but you've not copied your ssh public key onto the Git server. Use ssh-keygen to generate your key and copy it to Git server. Done! This solution also helps you never retype password on terminal again. See a good instruction by @Fnatical here for the answer.

这个答案后面更新的部分对你一点帮助都没有。(这实际上会让你的工作流程停滞不前。)它只是停止在Visual Studio Code中发生的事情,并将这些发生的事情移动到终端。

如果这个糟糕的答案影响了你很长很长一段时间,我很抱歉。


原来的答案(不好)

我在Visual Studio Code文档中找到了解决方案:

提示:您应该设置一个凭据助手,以避免被询问 每次VS Code与你的Git遥控器对话时,你都需要获取凭据。如果你 不要这样做,你可能想要考虑在… 菜单来减少提示的数量。

因此,打开凭据帮助程序,以便Git将密码保存在内存中一段时间。默认情况下,Git会缓存密码15分钟。

在Terminal中输入如下内容:

git config --global credential.helper cache
# Set Git to use the credential memory cache

输入如下命令修改默认密码缓存超时时间。

git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

如果原来的答案不成立

我安装了Visual Studio Code和上面相同的配置,但正如@ddieppa所说,它也不适合我。所以我试着在用户设置中找到一个选项,我看到了“git”。Autofetch " =真,现在设置为假!Visual Studio代码不再需要重复输入密码!

在菜单文件→首选项→用户设置: 类型:

将您的设置放在这个文件中以覆盖默认设置:

{
  "git.autofetch": false
}

我设法通过执行以下步骤来阻止这种情况。

卸载GitHub Desktop(我不确定这是必要的) 卸载凭证管理器:cd“C:\Program Files\Git\mingw64\libexec\ Git -core”,然后执行Git - Credentials - Manager .exe卸载 重置凭证帮助使用wincred: git config——global credential。辅助wincred 使用Visual Studio Code来推动一些更改并重新输入凭证。

注意:我使用个人访问令牌作为密码。

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

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

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

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

git config --global credential.helper wincred

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