我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
当前回答
克隆存储库repo后,可以编辑repo/.git/config并添加如下配置:
[user]
name = you_name
password = you_password
[credential]
helper = store
这样就不会再次要求您输入用户名和密码。
其他回答
克隆存储库repo后,可以编辑repo/.git/config并添加如下配置:
[user]
name = you_name
password = you_password
[credential]
helper = store
这样就不会再次要求您输入用户名和密码。
使用凭据存储。
对于OS X和Linux上的Git 2.11+,请使用Git内置的凭据存储:
git config --global credential.helper libsecret
对于Windows上的msysgit 1.7.9+:
git config --global credential.helper wincred
对于OS X上的Git 1.7.9+,请使用:
git config --global credential.helper osxkeychain
为了安全起见,最好使用凭据,但您可以使用缓存将其保存一段时间:
git config --global credential.helper cache
git config credential.helper 'cache --timeout=3600'
您的凭据将保存3600秒。
您可以使用凭据助手。
git config --global credential.helper 'cache --timeout=x'
其中x是秒数。
您还可以让Git使用Git凭据存储永久存储您的凭据,如下所示:
git config credential.helper store
注意:虽然这很方便,但Git会在项目目录下的本地文件(.git凭据)(参见下面的“home”目录)。如果不喜欢,请删除此文件并切换到使用缓存选项。
如果您希望Git恢复到每次需要时都向您请求凭据连接到远程存储库,可以运行以下命令:
git config --unset credential.helper
要将密码存储在%HOME%目录(而不是项目目录)中的.git凭据中,请使用--global标志
git config --global credential.helper store