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

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


当前回答

git config --global user.name "your username"
git config --global user.password "your password"

检查

git config --list

其他回答

在这种情况下,您需要git凭据助手通过以下命令行告诉git记住您的GitHub密码和用户名:

git config --global credential.helper wincred

如果您使用的是使用SSH密钥的存储库,则需要SSH密钥进行身份验证。

将用户名和密码存储在.git凭据中

.git credentials是运行git-config--globalcredential.helper store时存储用户名和密码(访问令牌)的位置,这是其他答案所建议的,然后键入用户名和密码或访问令牌:

https://${username_or_access_token}:${password_or_access_token}@github.com

因此,为了保存用户名和密码(访问令牌):

git config —-global credential.helper store
echo “https://${username}:${password_or_access_token}@github.com“ > ~/.git-credentials

这对于GitHub机器人非常有用,例如,通过为不同分支设置规则来解决同一Docker Hub存储库中的Chain自动化构建,然后通过在Docker Hub中的post_push钩子中推送该规则来触发它。

堆栈溢出就是一个例子。

如果您正在Windows上使用Git凭据管理器。。。

git-config-l应该显示:

credential.helper=manager

但是,如果没有提示您输入凭据,请执行以下步骤:

从“开始”菜单打开“控制面板”选择用户帐户在左侧菜单中选择管理凭据删除与Git或GitHub相关的任何凭据

如果您有代理并且Git服务器位于内部网络上,请确保您没有设置HTTP_PROXY、HTTPS_PROXY、NO_PROXY环境变量。

您还可以使用gitgui测试Git fetch/push/pull,gitgui链接到C:\Users\<username>\AppData\Local\Programs\Git\mingw64\libexec\Git-core中的凭据管理器二进制文件

您可以使用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