我开始使用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电脑上,那么安装Git for Windows。就是这样!

其他回答

打开Visual Studio Code的用户必须与执行Git命令的用户相同。然后在终端中执行如下命令。

git config --global credential.helper store
git pull

在下一个操作push或pull中,您将不会看到它请求Git凭据。

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

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

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

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

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

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

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

使用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键 粘贴密钥并保存

你都准备好了:-)