Visual Studio Code 总是要求提供 Git 凭据 [英] Visual Studio Code is always asking for Git credentials

查看:47
本文介绍了Visual Studio Code 总是要求提供 Git 凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用

我在弹出窗口中输入了我的 GitHub 凭据,但仍然在 Visual Studio Code 的 Git 输出窗口中收到此错误:

remote:拒绝匿名访问 ddieppa/LineOfBizApp.git.致命:https://github.com/ddieppa/LineOfBizApp.git/"的身份验证失败

解决方案

为什么 Visual Studio Code 要求输入密码?因为 Visual Studio Code 运行自动获取功能,而 Git 服务器没有任何信息来授权您的身份.它发生在:

  • 您的 Git 存储库有一个 https 远程 URL.是的!这种遥控器绝对每次都会问你.这里也不例外!(您可以使用以下解决方案临时缓存授权,但不建议这样做.)
  • 您的 Git 存储库具有 ssl 远程 URL,但是您尚未将 ssh 公钥复制到 Git 服务器上.使用 ssh-keygen 生成您的密钥并将其复制到 Git 服务器.完毕!此解决方案还可以帮助您不再在终端上重新输入密码.请参阅@Fnatical 此处 的一个很好的说明以获取答案.

此答案末尾的更新部分根本没有真正帮助您.(它实际上让您在工作流程中停滞不前.)它只会阻止 Visual Studio Code 中发生的事情,并将这些事情转移到终端.

如果这个糟糕的答案影响了你很长时间,很抱歉.

--

原答案(差)

我在 Visual Studio Code 文档上找到了解决方案:

<块引用>

提示:您应该设置凭证助手 以避免被问到每次 VS Code 与您的 Git 遥控器对话时获取凭据.如果你不要这样做,您可能需要考虑在 ...菜单以减少您收到的提示数量.

因此,打开凭证助手,以便 Git 将您的密码保存在内存中一段时间​​.默认情况下,Git 会将您的密码缓存 15 分钟.

在终端中,输入以下内容:

git config --global credential.helper 缓存# 设置 Git 使用凭证内存缓存

要更改默认密码缓存超时,请输入以下内容:

git config --global credential.helper 'cache --timeout=3600'# 设置缓存1小时后超时(设置以秒为单位)

如果原始答案不起作用

我安装了 Visual Studio Code,配置与上面相同,但正如@ddieppa 所说,它对我也不起作用.所以我试图在用户设置中找到一个选项,我看到了git.autofetch".= true,现在设置为false!Visual Studio Code 不再需要重复输入密码!

在菜单文件首选项用户设置:输入这些:

将您的设置放在此文件中以覆盖默认设置:

<代码>{git.autofetch":假}

I started using Visual Studio Code, and I was trying to save my test project into GitHub, but Visual Studio Code is always asking for my GitHub credentials.

I have installed in my PC GitHub Desktop and also Git. I already ran:

 git config --global credential.helper wincred

but still Visual Studio Code is asking for the credentials.

How can I fix this?

Here is my .gitconfig file located in the user profile folfer:

    [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

Here is the popup windows asking for the credentials:

I enter my GitHub credentials in the popup, but still getting this error in the Git output window in Visual Studio Code:

remote: Anonymous access to ddieppa/LineOfBizApp.git denied.
fatal: Authentication failed for 'https://github.com/ddieppa/LineOfBizApp.git/'

解决方案

Why does Visual Studio Code ask for a password? Because Visual Studio Code runs the auto-fetch feature, while the Git server doesn't have any information to authorize your identity. It happens when:

  • Your Git repository has a https remote URL. Yes! This kind of remote will absolutely ask you every time. No exceptions here! (You can do a temporary trick to cache the authorization as the solution below, but this is not recommended.)
  • Your Git repository has ssl remote URL, but you've not copied your ssh public key onto the Git server. Use ssh-keygen to generate your key and copy it to Git server. Done! This solution also helps you never retype password on terminal again. See a good instruction by @Fnatical here for the answer.

The updated part at the end of this answer doesn't really help you at all. (It actually makes you stagnant in your workflow.) It only stops things happening in Visual Studio Code and moves these happenings to the terminal.

Sorry if this bad answer has affected you for a long, long time.

--

The original answer (bad)

I found the solution on Visual Studio Code document:

Tip: You should set up a credential helper to avoid getting asked for credentials every time VS Code talks to your Git remotes. If you don't do this, you may want to consider Disabling Autofetch in the ... menu to reduce the number of prompts you get.

So, turn on the credential helper so that Git will save your password in memory for some time. By default, Git will cache your password for 15 minutes.

In Terminal, enter the following:

git config --global credential.helper cache
# Set Git to use the credential memory cache

To change the default password cache timeout, enter the following:

git config --global credential.helper 'cache --timeout=3600'
# Set the cache to timeout after 1 hour (setting is in seconds)

If the original answer doesn't work

I installed Visual Studio Code and configuration same above, but as @ddieppa said, It didn't work for me too. So I tried to find an option in User Setting, and I saw "git.autofetch" = true, now set it's false! Visual Studio Code is no longer required to enter password repeatedly again!

In menu FilePreferencesUser Setting: Type these:

Place your settings in this file to overwrite the default settings:

{
  "git.autofetch": false
}

这篇关于Visual Studio Code 总是要求提供 Git 凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆