我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
对于Windows用户,这种方式将起作用:
注意:如果您为GitHub启用了双因素身份验证,请暂时禁用它
步骤1转到控制面板→ 用户帐户→ 凭据管理器→ Windows凭据步骤2转到“通用凭据”部分→ 添加通用凭据步骤3-填写字段Internet或网络地址:git。https://github.com用户名:您的GitHub用户名密码:您的GitHub用户名现在单击“确定”。这将将您的GitHub帐户的密码和用户名保存到本地计算机
其他回答
我认为缓存凭据比永久存储更安全:
git config --global credential.helper 'cache --timeout=10800'
现在,您可以输入用户名和密码(git pull或…),并在接下来的三个小时内继续使用git。
它很好,很安全。
超时的单位是秒(在本例中为三小时)。
打开凭据助手,以便Git将您的密码保存在内存中一段时间:
在终端中,输入以下内容:
# Set Git to use the credential memory cache
git config --global credential.helper cache
默认情况下,Git将缓存您的密码15分钟。
要更改默认密码缓存超时,请输入以下内容:
# Set the cache to timeout after 1 hour (setting is in seconds)
git config --global credential.helper 'cache --timeout=3600'
来自GitHub帮助。
您可以使用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将凭据存储在磁盘上。
根据rofrol在Linux Ubuntu上的评论,根据这个答案,下面是如何在Ubuntu上实现的:
sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
其他一些发行版提供二进制文件,因此您不必构建它。
在OSX中,它通常“内置”了一个默认模块“osxkeychain”,因此您可以免费获得它。默认情况下,OS X内置和自制版本都有它。
对于Windows用户,请查看.gitconfig文件并检查为凭据助手配置了什么。如果您有以下内容。。。
[凭证“helperselector”]selected=绞车
您将在Windows凭据管理器中找到凭据。
您可以在那里编辑凭证。
注意:Wincred已被弃用,请参阅。。。
https://github.com/Microsoft/Git-Credential-Manager-for-Windows#notice-该项目不再处于警告状态
因此,您可能需要重新配置Git以使用内置的Git凭据管理器。。。
git config --global credential.helper manager