我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
我最近切换到将我的存储库同步到GitHub上的https://(由于防火墙问题),它每次都会要求输入密码。
有没有办法缓存凭据,而不是每次git推送时都进行身份验证?
当前回答
您可以使用凭据助手。
git config --global credential.helper 'cache --timeout=x'
其中x是秒数。
其他回答
只需将登录凭据作为URL的一部分:
git remote rm origin
git remote add origin https://username:mypassword@github.com/path/to/repo.git
注意:我不建议使用这种方法,但如果你很匆忙,而其他方法都不奏效,你可以使用这种方法。
您可以使用凭据助手。
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
为了安全起见,最好使用凭据,但您可以使用缓存将其保存一段时间:
git config --global credential.helper cache
git config credential.helper 'cache --timeout=3600'
您的凭据将保存3600秒。
克隆存储库repo后,可以编辑repo/.git/config并添加如下配置:
[user]
name = you_name
password = you_password
[credential]
helper = store
这样就不会再次要求您输入用户名和密码。