我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。

那么我如何在Git中保存我的凭据?


当前回答

对于Windows用户,请查看.gitconfig文件并检查为凭据助手配置了什么。如果您有以下内容。。。

[凭证“helperselector”]selected=绞车

您将在Windows凭据管理器中找到凭据。

您可以在那里编辑凭证。

注意:Wincred已被弃用,请参阅。。。

https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-该项目不再处于警告状态

因此,您可能需要重新配置Git以使用内置的Git凭据管理器。。。

git config --global credential.helper manager

其他回答

您可以使用git凭据存储将未加密的密码存储在磁盘上,仅受文件系统权限的保护。

实例

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凭据中的凭据。

有关更多信息,请访问git credential store-Helper将凭据存储在磁盘上。

双因素身份验证改变了用户对网站的身份验证方式,但Git仍然假设用户可以从内存中键入密码。

介绍git credential oauth:一个git凭据助手,可以使用oauth安全认证GitHub、GitLab、BitBucket和其他伪造文件。

没有更多密码!不再有个人访问令牌!不再有SSH密钥!第一次推送时,助手将打开浏览器窗口进行身份验证。缓存超时内的后续推送不需要交互。

从安装https://github.com/hickford/git-credential-oauth/releases/

配置方式:

git config --global --unset-all credential.helper
git config --global --add credential.helper "cache --timeout 7200" # two hours
git config --global --add credential.helper oauth

以前的答案对我来说都不管用。每次我想取东西或拉东西时,我都会得到以下答案:

输入密钥“/Users/myusername/.ssh/id_rsa”的密码:


适用于Mac

我可以通过以下方式阻止它询问我的密码:

通过运行:vi~/.ssh/config打开config添加了以下内容:UseKeychain yes保存并退出:按Esc,然后输入:wq!


对于Windows

我能够使用此Stack Exchange帖子中的信息使其发挥作用:如何避免每次推到Bitbucket时被询问密码

对于有相同问题的gitlab用户-

您可以设置一个部署令牌来克隆或从存储库中提取(不能使用部署令牌将代码推送到repo)。

在这里,您可以了解有关gitlab部署令牌的更多信息:https://docs.gitlab.com/ee/user/project/deploy_tokens/index.html

创建部署令牌后,请使用以下方法克隆回购:

git clone https://${username}:${deploy_token}@gitlab.com/yourusername/yourreponame.git

我认为这种方法比全局保存git用户名和git密码更好(例如,在远程共享计算机中可能不安全)

只需使用

git config --global credential.helper store

然后做数字拉动。它将要求输入用户名和密码。从现在起,它将不会提供任何用户名和密码提示。它将存储详细信息。