我开始使用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服务器没有任何信息来授权您的身份。它发生在:

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
}

其他回答

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

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

git config --global credential.helper wincred

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

为什么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
}

Ubuntu用户只需在Visual Studio Code终端输入以下命令:

git config --global credential.helper store

现在,输入一次你的用户名和密码,之后它就不会再问你了。

注意:

用户名和密码不加密,以纯文本形式存储,请谨慎使用。 但是,如果您的密码包含一些特殊字符,如@,#,&,*等,那么这些字符将被加密。

此外,你可以找到你的'。Git-credentials文件在家里。它是隐藏的,所以一定要启用隐藏文件。

地点:~ / .git-credentials

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

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

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

请按照以下步骤进行处理。

卸载Visual Studio Code和Git软件,然后重新安装。将Git存储库克隆URL从SSH更改为HTTPS。