【发布时间】:2011-01-15 01:41:57
【问题描述】:
我正在使用 Git 将更改推送到通过 HTTP / WebDAV 共享的存储库,并且 Git 会提示为访问 HTTP 远程的每个操作输入密码。有没有办法让Git缓存密码/远程服务器不提示我?
远程网络服务器应该是 Apache 并且可以在必要时重新配置。
【问题讨论】:
我正在使用 Git 将更改推送到通过 HTTP / WebDAV 共享的存储库,并且 Git 会提示为访问 HTTP 远程的每个操作输入密码。有没有办法让Git缓存密码/远程服务器不提示我?
远程网络服务器应该是 Apache 并且可以在必要时重新配置。
【问题讨论】:
方法是按照this Git documentation的第3步所述使用~/.netrc:
然后,将以下内容添加到您的 $HOME/.netrc 中(您可以不添加,但将 要求输入您的密码很多次):
machine <servername> login <username> password <password>...并设置权限:
chmod 600 ~/.netrc
从 git 1.7.9 开始,似乎要走的路是原生凭证助手 API。 Git 带有明文credential store 或不太方便但更安全的临时credential cache。也可以使用第三方凭证助手。到目前为止,我知道a helper for the native Windows Credential Store 和one that integrates with the OS X keychain。 (Homebrew 发布的 Git 版本有一个二进制文件,其他 OS X Git 发行版也有。Github 还提供了一个standalone binary。)
一般来说,设置一次凭证助手就足够了:
git config --global credential.helper wincred
或者代替wincred,使用适合您平台的任何帮助程序。 (如果帮助程序可执行文件的名称是git-credential-wincred,则您设置的选项值将是wincred,等等)
凭证助手还支持为同一主机上的不同存储库拥有单独的凭证集的需要。
【讨论】:
~/.netrc。
在你的仓库中运行这个命令:
git config credential.helper store
然后推送到服务器一次:
git push
您用来推送到服务器的凭据将保存在~/.git-credentials。
取自本指南here的说明。
【讨论】:
为什么不能只在远程 url 中使用密码?
$ git config remote.origin.url = http://username:password@origin_link.com/repository.git
【讨论】:
~/.netrc 不是世界可读的而不是为每个.git/config 这样做)