我开始使用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远程URL从HTTPS更改为SSH:

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

其他回答

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

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

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

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

这对我很有用。你只需要输入一次PAT。 Git配置——全局凭据。辅助wincred

相反的问题,但相关的:

在我的情况下,我努力与Visual Studio Code集成终端不忘记输入的密码,即使缓存助手超时已经过期。

不过,外部终端会话工作正常。

我发现在Visual Studio Code中有一个选项,它允许你在实际的Git插件上设置一个可选的缓存,这并不允许预期的行为发生。

一旦检查,我的密码在缓存超时时就被忘记了,所以我可以毫不费力地从个人账户跳到工作账户:)

Linux和Visual Studio Code 1.58.2。

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

git config --global credential.helper store
git pull

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