bash 在 Windows 上添加 Git 凭据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46878457/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:37:02  来源:igfitidea点击:

Adding Git credentials on Windows

gitbashgithub

提问by PJ Tikalsky

I am on a Windows 10 system and am trying to add my credentials to Git in Git Bash. I cannot find a way to store my password.

我在 Windows 10 系统上,正在尝试将我的凭据添加到 Git Bash 中的 Git。我找不到存储密码的方法。

I checked GitHub's documentation, which said just to enter the line git config --global credential.helper wincred, but that didn't seem to make sense, as there's not prompt to enter a password. I checked Git's documentation, which said to use command git credential-store --file ~/git.store storeand fill in all prompts. The bash emulator wasn't able to read the credentials.

我查看了 GitHub 的文档,它说只是输入该行git config --global credential.helper wincred,但这似乎没有意义,因为没有提示输入密码。我查看了 Git 的文档,其中说使用命令git credential-store --file ~/git.store store并填写所有提示。bash 模拟器无法读取凭据。

Finally, I tried to add my password like I added my email, via git config --global user.password "5ecre7"but after running a sample git clone on a repository I made it responded that I didn't have the access rights. Is there a way to fix this?

最后,我尝试像添加电子邮件一样添加密码,git config --global user.password "5ecre7"但在存储库上运行示例 git clone 后,我做出响应,说我没有访问权限。有没有办法来解决这个问题?

回答by VonC

Ideally, you should enter:

理想情况下,您应该输入:

git config --global credential.helper manager

Then your password would be stored in the Windows Credential Manager.
See more at "Unable to change git account".

然后您的密码将存储在 Windows 凭据管理器中。
在“无法更改 git 帐户”中查看更多信息。

On the first push, a popup will appear asking for your credentials (username/password) for the target server (for instance github.com)

在第一次推送时,将出现一个弹出窗口,要求您提供目标服务器的凭据(用户名/密码)(例如github.com

If not, that might means your credentials were alreadystored.
If they are incorrect, a simple git credential-manager reject https://github.comwill remove them (on Windows, again. On Mac: git credential-osxkeychain erase https://github.com)

如果没有,那可能意味着您的凭据已经存储。
如果他们是不正确的,简单的git credential-manager reject https://github.com将(再次在Windows上。删除它们在Mac: git credential-osxkeychain erase https://github.com

回答by Raza Mehdi

I normally prefer to clone my Git repositories using SSH links. Here are my steps for Windows:

我通常更喜欢使用 SSH 链接克隆我的 Git 存储库。以下是我的 Windows 步骤:

  • Generate a public/private key pair through PuTTYgen.
  • Add the public key to my GitHub account.
  • 通过PuTTYgen生成公钥/私钥对。
  • 将公钥添加到我的 GitHub 帐户。

By doing this, I can easily clone my repositories without needing to use my GitHub account password.

通过这样做,我可以轻松地克隆我的存储库,而无需使用我的 GitHub 帐户密码。