每当我尝试推入我的存储库时,git都会要求用户名和密码。
每次重新输入密码没有问题,但问题是输入用户名。我使用https克隆存储库。
那么,我如何配置git,使它在每次git推送时都不需要用户名。
我是linux新手,但windows git push中的IIRC只要求输入密码。
每当我尝试推入我的存储库时,git都会要求用户名和密码。
每次重新输入密码没有问题,但问题是输入用户名。我使用https克隆存储库。
那么,我如何配置git,使它在每次git推送时都不需要用户名。
我是linux新手,但windows git push中的IIRC只要求输入密码。
当前回答
使用Git存储库永久验证
运行以下命令以启用凭据缓存:
$ git config credential.helper store
$ git push https://github.com/repo.git
Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>
使用还应指定缓存过期
git config --global credential.helper "cache --timeout 7200"
启用凭据缓存后,将缓存7200秒(2小时)。
读取凭证文档
$ git help credentials
其他回答
快速方法
在工作目录中获取git的url:
git config remote.origin.url
那么:
git config credential.helper store
git push "url of your git"
将最后一次询问用户名和密码
完成。
如果您使用的是https而不是ssh,您可以按照user701648所说的那样在.git/config中编辑“url”,但如果您愿意,也可以添加密码:
url = https://username:password@repository-url.com
(仅适用于Mac OS)
对于Windows和Linux,请参阅下面提到的Github文档链接。
来自Github文档:文档链接
在Git中缓存GitHub密码
您需要Git 1.7.10或更高版本才能使用osxkeychain凭据帮手检查Git版本:Git--version要了解osxkeychain助手是否已安装:git凭证osxkeychain如果您收到以下响应,那么您已经安装并准备好在mac上使用:>用法:git credential osxkeychain<get|store|erase>如果您没有得到如上所示的响应,则可以运行以下命令安装它:git凭证osxkeychain要告诉git全局使用osxkeychain获取git凭据:git-config--全局凭证.helper osxkeychain在将凭据保存到密钥链之前,它将提示一次。
除了user701648的答案之外,您还可以使用以下命令将凭据存储在主文件夹(所有项目的全局文件夹)中,而不是项目文件夹中
$ git config --global credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
更改克隆的存储库可以:
git remote set-url origin git@github.com:gitusername/projectname.git
使用缓存的凭据是有效的,设置超时时间可以减少麻烦。如果您使用Windows凭据助手,这应该是最简单的方法(特别是在SSH被阻止的情况下)。