我开始使用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 remote set-url origin https://<USERNAME>:<PASSWORD>@bitbucket.org/path/to/repo.git

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

git config --get remote.origin.url

其他回答

您可以参考此链接来设置Git凭据。

您可以运行以下命令来保存Git凭据。你不需要每次运行Git命令时都输入用户名和密码(适用于Windows):

git config --global credential.helper wincred

对于Mac / Linux,如何保存Git凭据,请参见Mac和Linux的Git凭据管理器。

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

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

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

git config --global credential.helper store
git pull

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

下面这篇文章:

您可以将GIT_SSH环境变量设置为PuTTY的plink.exe程序。

(然后使用pageant.exe程序作为身份验证代理。)

如果你是在Windows电脑上,那么安装Git for Windows。就是这样!