我开始使用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配置——全局凭据。辅助存储

或者,如果你在Windows上,你可以使用他们的证书系统:

Git配置——全局凭据。辅助wincred

或者,如果你在macOS上,你可以使用他们的凭据系统:

Git配置——全局凭据。辅助osxkeychain

第一种解决方案在大多数情况下是最优的。

其他回答

使用SSH代替HTTP或HTTPS。

您需要在您的本地机器上设置SSH密钥,将它们上传到您的Git服务器,并将URL从http://替换为Git://,您将不再需要使用密码。

如果你不能使用ssh添加到你的配置:

[credential "https://example.com"]
    username = me

文件在这里。


在GitHub中使用SSH密钥


简单地按照这些步骤,你将设置你的SSH密钥在任何时间:

生成一个新的SSH密钥(如果已经有密钥,则跳过此步骤) ssh -t rsa -C "your@email" 一旦你在家里设置好了钥匙。ssh目录(或Users/<您的用户>。ssh),打开并复制内容


如何向GitHub帐户添加SSH密钥?

登录GitHub账户 点击右上角的牧场主(设置) GitHub账户设置http://git-scm.com/docs/gitcredentials 单击SSH密钥 单击Add ssh键 粘贴密钥并保存

你都准备好了:-)

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

我通常运行这个简单的命令来将Git远程URL从HTTPS更改为SSH:

git remote set-url origin git@github.com:username/repo-name-here.git

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

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

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