Visual Studio Code 总是要求提供 git 凭据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34400272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Code always asking for git credentials
提问by ddieppa
I started using Visual Studio Code, and I was trying to save my test project into GitHub, but Visual Studio Codeis always asking for my GitHubcredentials.
我开始使用Visual Studio Code,我试图将我的测试项目保存到GitHub,但Visual Studio Code总是要求我提供GitHub凭据。
I have installed in my PC GitHub Desktopand also Git, I already ran:
我已经安装在我的 PC GitHub Desktop和Git 中,我已经运行了:
git config --global credential.helper wincred
but still Visual Studio Codeis asking for the credentials.
但Visual Studio Code仍然要求提供凭据。
Any help?
有什么帮助吗?
here is my .gitconfigfile located in the user profile folfer:
这是我位于用户配置文件文件夹中的.gitconfig文件:
[filter "lfs"]
clean = git-lfs clean %f
smudge = git-lfs smudge %f
required = true
[user]
name = ddieppa
[user]
email = [email protected]
[credential]
helper = wincred
Here is the popup windows asking for the credentials:
这是要求凭据的弹出窗口:
I enter my GitHubcredentials in the popup, but still getting this error in the Gitoutput window in Visual Studio Code:
我在弹出窗口中输入了我的GitHub凭据,但在Visual Studio Code的Git输出窗口中仍然收到此错误:
remote: Anonymous access to ddieppa/LineOfBizApp.git denied.
fatal: Authentication failed for 'https://github.com/ddieppa/LineOfBizApp.git/'
回答by Davuz
Last updated: 05 March, 2019
最后更新:2019 年 3 月 5 日
After 98 upvotes, I think I need to give a true answer with the explanation.
98个赞后,我想我需要给出一个真实的答案和解释。
Why does VS code ask for a password? Because VSCode runs the auto-fetch feature, while git server doesn't have any information to authorize your identity. It happens when:
为什么 VS 代码要求输入密码?因为 VSCode 运行自动获取功能,而 git 服务器没有任何信息来授权您的身份。它发生在:
- Your git repo has
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 repo has
ssl
remote url, BUT you've not copied your ssh public key onto git server. Usessh-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 herefor the answer.
- 你的 git repo 有
https
远程 url。是的!这种遥控器绝对每次都会问你。这里没有例外!(你可以做一个临时的技巧来缓存授权,如下解决方案,但不推荐这样做。) - 您的 git repo 具有
ssl
远程 url,但您尚未将 ssh 公钥复制到 git 服务器上。使用ssh-keygen
生成的密钥,并将其复制到服务器的Git。完毕!此解决方案还可以帮助您不再在终端上重新输入密码。请在此处查看@Fnatical 的一个很好的说明以获取答案。
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 VSCode and moves these happenings to the terminal.
此答案末尾的更新部分根本对您没有帮助。(它实际上让您在工作流程中停滞不前。)它只会阻止 VSCode 中发生的事情并将这些事情移动到终端。
Sorry if this bad answer has affected you for a long, long time.
如果这个糟糕的答案影响了你很长时间,很抱歉。
--
——
the original answer (bad)
原来的答案(不好)
I found the solution on VSCode document:
我在VSCode 文档中找到了解决方案:
Tip: You should set up a credential helperto 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.
提示:您应该设置一个凭证助手,以避免每次 VS Code 与您的 Git 遥控器对话时都被要求提供凭证。如果您不这样做,您可能需要考虑在 ... 菜单中禁用 Autofetch 以减少您收到的提示数量。
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.
因此,打开凭证助手,以便 Git 将您的密码保存在内存中一段时间。默认情况下,Git 会将您的密码缓存 15 分钟。
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)
UPDATE (If original answer doesn't work)
更新(如果原始答案不起作用)
I installed VS Code and config 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! VS Code is no longer required to enter password repeatedly again!
我安装了与上面相同的 VS Code 和配置,但正如@ddieppa 所说,它对我也不起作用。所以我试图在用户设置中找到一个选项,我看到“git.autofetch”=true,现在将其设置为false!VS Code 不再需要重复输入密码了!
In menu, click File / Preferences / User Setting And type these:
在菜单中,单击文件/首选项/用户设置并键入这些:
Place your settings in this file to overwrite the default settings
将您的设置放在此文件中以覆盖默认设置
{
"git.autofetch": false
}
回答by yohosuff
You should be able to set your credentials like this:
您应该能够像这样设置您的凭据:
git remote set-url origin https://<USERNAME>:<PASSWORD>@bitbucket.org/path/to/repo.git
git remote set-url origin https://<USERNAME>:<PASSWORD>@bitbucket.org/path/to/repo.git
You can get the remote url like this:
您可以像这样获取远程网址:
git config --get remote.origin.url
git config --get remote.origin.url
回答by Vaibhav Vishal
This has been working for me:
1. Set credential hepler to store$ git config --global credential.helper store
2. then verify if you want:$ git config --global credential.helper
store
这对我
有用:1. 将凭证 hepler 设置为存储$ git config --global credential.helper store
2. 然后验证是否需要:$ git config --global credential.helper
store
Simple example when using git bash quoted from Here(works for current repo only, use --global
for all repos)
使用从这里引用的 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]
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: < type your username >
Password: < type your password >
[几天后]
$ git push http://example.com/repo.git
[您的凭据将自动使用]
Will work for VS Code too.
也适用于 VS Code。
More detailed example and advanced usage here.
更详细的示例和高级用法在这里。
Note:Username & Passwords are not encrypted and stored in plain text format so use it on your personal computer only.
注意:用户名和密码未加密并以纯文本格式存储,因此只能在您的个人计算机上使用。
回答by Fnatical
The following steps walk you through how to:
以下步骤将指导您完成以下操作:
- Generate SSH keys (without passphrase**)
- Add the public key generated in step 1 to your Git repository
- Confirm the above steps have been completed successfully
- Make your first commit (without having to provide a username / password)
- 生成 SSH 密钥(不带密码**)
- 将步骤 1 中生成的公钥添加到您的 Git 存储库中
- 确认以上步骤已成功完成
- 进行第一次提交(无需提供用户名/密码)
**Generating SSH keys without a passphrase is unwise if your work is particularly sensitive.
**如果您的工作特别敏感,则在没有密码的情况下生成 SSH 密钥是不明智的。
OS- Fedora 28 | Editor- VS Code v1.23.0 | Repository- Git
操作系统- Fedora 28 | 编辑器- VS Code v1.23.0 | 存储库- Git
Generate SSH keys:
生成 SSH 密钥:
ssh-keygen -t rsa -C "[email protected]"
- Enter file in which to save the key: Press Enter
- Enter passphrase: Press Enter
- Enter same passphrase again: Press Enter
ssh-keygen -t rsa -C "[email protected]"
- 输入要保存密钥的文件:按 Enter
- 输入密码:按 Enter
- 再次输入相同的密码:按 Enter
After completing the above steps, the location of your public key is shown in the terminal window. If the currently logged in user is 'bob' the location of your public key would be /home/bob/.ssh/id_rsa.pub
完成上述步骤后,您的公钥位置将显示在终端窗口中。如果当前登录的用户是“bob”,则您的公钥的位置将是/home/bob/.ssh/id_rsa.pub
Copy and import public key to GitHub:
将公钥复制并导入到 GitHub:
cat /home/bob/.ssh/id_rsa.pub
Copy the whole public key that is now displayed in your terminal window to the clipboard
- Go to https://github.comand sign in
- Click the user icon in the top right corner of the screen and select Settings
- Click SSH and GPG keys
- Click New SSH key
- Enter a title, paste the public key copied to the clipboard in the first bullet point, and click Add SSH key
cat /home/bob/.ssh/id_rsa.pub
将现在显示在终端窗口中的整个公钥复制到剪贴板
- 去https://github.com并登录
- 单击屏幕右上角的用户图标,然后选择设置
- 单击SSH 和 GPG 密钥
- 单击新建 SSH 密钥
- 输入标题,将复制到剪贴板的公钥粘贴到第一个项目符号点,然后单击添加 SSH 密钥
Confirm the above steps:
确认以上步骤:
ssh -T [email protected]
yes
Hi ! You've successfully authenticated, but GitHub does not provide shell access.
ssh -T [email protected]
yes
你好 !您已成功通过身份验证,但 GitHub 不提供 shell 访问。
First commit / push without having to enter a username / password:- touch test.txt
第一次提交/推送而无需输入用户名/密码:-touch test.txt
git add test.txt
git commit
- opens editor, enter a message and save the file. If vi is your editor, pressi
once the file opens, enter a message, press esc, and then enter:x
to save changes.git push
git add test.txt
git commit
- 打开编辑器,输入消息并保存文件。如果 vi 是您的编辑器,请i
在文件打开后按,输入消息,按 esc,然后按 Enter:x
保存更改。git push
The only hiccup you may encounter is when you attempt to SSH to GitHub. This link will provide some assistance -
您可能会遇到的唯一问题是当您尝试通过 SSH 连接到 GitHub 时。此链接将提供一些帮助 -
Happy hunting!
狩猎快乐!
回答by GoTo
All I had to do was to run this command:
我所要做的就是运行这个命令:
git config --global credential.helper wincred
git config --global credential.helper wincred
Then I was prompted for password twice.
然后我被提示输入密码两次。
Next time it worked without prompting me for password.
下次它在不提示我输入密码的情况下工作。
回答by Reddog
Try installing "Git Credential Manager For Windows" (and following instructions for setting up the credential manager).
尝试安装“ Git Credential Manager For Windows”(并按照设置凭据管理器的说明进行操作)。
When required within an app using Git (e.g. VS Code) it will "magically" open the required dialog for Visual Studio Team Services credential input.
在使用 Git(例如 VS Code)的应用程序中需要时,它将“神奇地”打开所需的 Visual Studio Team Services 凭据输入对话框。
回答by CodeWizard
Use ssh instead of http/https.
使用 ssh 而不是 http/https。
You will need to set ssh keys on your local machine, upload them to your git server and replace the url form http://
to git://
and you will not need to use passwords anymore.
您需要在本地机器上设置 ssh 密钥,将它们上传到您的 git 服务器并将 url 表单替换http://
为git://
,您将不再需要使用密码。
If you cant use ssh add this to your config:
如果您不能使用 ssh,请将其添加到您的配置中:
[credential "https://example.com"]
username = me
documents are here.
文件在这里。
Using ssh key in github
在 github 中使用 ssh 密钥
Simply follow those steps and you will set up your ssh key in no time:
只需按照这些步骤操作,您就可以立即设置 ssh 密钥:
Generate a new ssh key (or skip this step if you already have a key)
ssh-keygen -t rsa -C "your@email"
Once you have your key set in
home/.ssh
directory (orUsers/<your user>.ssh
under windows), open it and copy the content
生成一个新的 ssh 密钥(如果您已经有密钥,则跳过此步骤)
ssh-keygen -t rsa -C "your@email"
在
home/.ssh
目录中(或Users/<your user>.ssh
在 Windows 下)设置密钥后,打开它并复制内容
How to add sh key to github account?
如何将 sh 密钥添加到 github 帐户?
- Login to github account
- Click on the rancher on the top right (Settings)
- Click on the
SSH keys
- Click on the
Add ssh key
- Paste your key and save
- 登录github账号
- 点击右上角的牧场主(设置)
- 点击
SSH keys
- 点击
Add ssh key
- 粘贴您的密钥并保存
And you all set to go :-)
你们都准备好了:-)
回答by Adam Erickson
In general, you can use the built-in credential storage facilities:
通常,您可以使用内置的凭证存储设施:
git config --global credential.helper store
git config --global credential.helper store
Or, if you're on Windows, you can use their credential system:
或者,如果您使用的是 Windows,则可以使用他们的凭证系统:
git config --global credential.helper wincred
git config --global credential.helper wincred
Or, if you're on MacOS, you can use their credential system:
或者,如果您使用的是 MacOS,则可以使用他们的凭证系统:
git config --global credential.helper osxkeychain
git config --global credential.helper osxkeychain
The first solution is optimal in most situations.
在大多数情况下,第一种解决方案是最佳的。
回答by Mark
Automatic Git authentication. From the v1.45 Release Notes:
自动 Git 身份验证。从 v1.45发行说明:
GitHub authentication for GitHub Repositories
VS Code now has automatic GitHub authentication against GitHub repositories. You can now clone, pull, push to and from public and private repositories without configuring any credential manager in your system. Even Git commands invoked in the Integrated Terminal, for example git push, are now automatically authenticated against your GitHub account.
You can disable GitHub authentication with the
git.githubAuthentication
setting. You can also disable the terminal authentication integration with thegit.terminalAuthentication
setting.
GitHub 存储库的 GitHub 身份验证
VS Code 现在具有针对 GitHub 存储库的自动 GitHub 身份验证。您现在可以在公共和私有存储库之间进行克隆、拉取、推送,而无需在系统中配置任何凭证管理器。即使是在集成终端中调用的 Git 命令,例如 git push,现在也会根据您的 GitHub 帐户自动进行身份验证。
您可以使用
git.githubAuthentication
设置禁用 GitHub 身份验证 。您还可以通过设置禁用终端身份验证集成git.terminalAuthentication
。
回答by Meera
For windows 10 : go to control panel/Credential manager/ Windows Credential--> click on the git link, --> edit--> update to new password. That should work
对于 Windows 10:转到控制面板/凭据管理器/Windows 凭据--> 单击 git 链接,--> 编辑--> 更新为新密码。那应该工作