我开始使用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。就是这样!

其他回答

你应该能够像这样设置你的凭证:

git remote set-url origin https://<USERNAME>:<PASSWORD>@bitbucket.org/path/to/repo.git

你可以像这样获取远程URL:

git config --get remote.origin.url

使用不带密码短语的SSH密钥。

也许这对一些人来说是显而易见的(对我来说不是)。如果你绝对需要密码,这也不能解决问题,但在我使用Mac的情况下,这是一个不错的妥协。

这对我来说很管用:

设置凭证帮助存储: Git配置——全局凭据。辅助存储 然后验证你是否想: Git配置——全局凭据。辅助存储

这里引用了一个使用Git Bash的简单示例(仅适用于当前存储库,对所有存储库使用——global):

git config credential.helper store
git push http://example.com/repo.git

Username: < type your username >
Password: < type your password >

[several days later]

git push http://example.com/repo.git

[your credentials are used automatically]

它也适用于Visual Studio Code。

这里有一个更详细的示例和高级用法。

注意:用户名和密码不加密,以纯文本格式存储,因此仅在您的个人计算机上使用。

我们需要配置VS Code以在Git命令之上提供身份验证。

下面我将展示如何设置扩展设置。

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

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