我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
我想在GitExtensions、Sourcetree或任何其他GitGUI中自动使用推拉,每次都不需要在提示中输入用户名和密码。
那么我如何在Git中保存我的凭据?
当前回答
要将用户名和用户密码保存到github帐户中,只需按顺序运行这些命令。
git config --global user.name "userName"
git config --global user.email "usernam@gmail.com"
git config --global user.password "userPassword"
git config --global credential.helper store
git config --list --show-origin
然后使用以下命令生成密钥:
ssh-keygen -t rsa -C "useremail@gmail.com"
注意:复制创建id_rsa文件的文件位置然后转到该文件位置-->打开gitbash或命令提示符-->运行命令-cat id_rsa.pub
将显示SSH密钥,复制此SSH密钥并将其粘贴到gihub/gitlab帐户中
其他回答
您可以使用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将您的密码保存在内存中一段时间:
在终端中,输入以下内容:
# 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 config --global credential.helper 'cache --timeout=10800'
现在,您可以输入用户名和密码(git pull或…),并在接下来的三个小时内继续使用git。
它很好,很安全。
超时的单位是秒(在本例中为三小时)。
以前的答案对我来说都不管用。每次我想取东西或拉东西时,我都会得到以下答案:
输入密钥“/Users/myusername/.ssh/id_rsa”的密码:
适用于Mac
我可以通过以下方式阻止它询问我的密码:
通过运行:vi~/.ssh/config打开config添加了以下内容:UseKeychain yes保存并退出:按Esc,然后输入:wq!
对于Windows
我能够使用此Stack Exchange帖子中的信息使其发挥作用:如何避免每次推到Bitbucket时被询问密码
除了编辑~/.gitconfig文件外,如果从命令行调用,还可以执行以下操作:
git config --local --edit
or
git config --global --edit
在默认文本编辑器中编辑git配置文件
您还可以使用命令行直接编辑git配置文件(无需编辑器)
git config --local user.name 'your username'
git config --local user.password 'your password'
or
git config --global user.name 'your username'
git config --global user.password 'your password'
请注意,始终使用单引号。如果您使用双引号,您的用户名和密码可能会使用一些会破坏密码的字符。
--local或--global表示为项目或OS用户保存配置参数。