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

当前回答

Windows 10操作系统:进入控制面板→凭证管理器→Windows凭证→点击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
}

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

卸载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认证。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程序作为身份验证代理。)

对于我来说,我已经用SSH密钥设置了远程存储库,但是Git无法找到它们,因为HOMEDRIVE环境变量由于公司的域策略被自动设置为网络共享。在启动代码之前更改shell中的环境变量。导致Visual Studio Code继承正确的环境变量和voilà在Git输出窗口中不再有连接错误。

现在我只需要弄清楚如何覆盖域策略,因此HOMEDRIVE总是指向我的本地c:\users\marvhen目录,这是.ssh目录的默认位置。