有没有办法让 git 记住 WebDAV 遥控器的密码?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2233590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:49:43  来源:igfitidea点击:

Is there a way to make git remember the password for WebDAV remotes?

gitpasswords

提问by millimoose

I'm working with Git pushing changes to a repository shared over HTTP / WebDAV, and Git prompts for a password for every operation that accesses the HTTP remote. Is there any way to make Git cache the password / have the remote server not prompt me?

我正在使用 Git 将更改推送到通过 HTTP/WebDAV 共享的存储库,并且 Git 会为访问 HTTP 远程的每个操作提示输入密码。有没有办法让 Git 缓存密码/让远程服务器不提示我?

The remote webserver should be an Apache and could possibly be reconfigured if necessary.

远程网络服务器应该是 Apache,如有必要,可以重新配置。

回答by millimoose

The way is to use ~/.netrc as outlined in step 3 of this Git documentation:

方法是使用 ~/.netrc ,如本 Git 文档的第 3 步所述:

Then, add the following to your $HOME/.netrc (you can do without, but will be asked to input your password a lotof times):

machine <servername>
login <username>
password <password>

...and set permissions:

chmod 600 ~/.netrc

然后,将以下内容添加到您的 $HOME/.netrc (您可以不这样做,但会要求输入您的密码很多次):

machine <servername>
login <username>
password <password>

...并设置权限:

chmod 600 ~/.netrc

UPDATE:

更新:

As of git 1.7.9, it seems the way to go would be the native credential helper API. Git comes with a plaintext credential storeor a less convenient but more secure temporary credential cache. It's also possible to use third-party credential helpers. So far I'm aware of a helper for the native Windows Credential Store, and one that integrates with the OS X keychain. (The Git build shipped by Homebrew has a binary for it, as might other OS X Git distributions. Github also provides a standalone binary.)

从 git 1.7.9 开始,似乎要走的路是本机凭证助手 API。Git 带有一个纯文本凭证存储或一个不太方便但更安全的临时凭证缓存。也可以使用第三方凭证助手。到目前为止,我知道本机 Windows Credential Store 的助手,以及与 OS X keychain 集成的助手。(Homebrew 提供的 Git 构建有一个二进制文件,其他 OS X Git 发行版也可能如此。Github 还提供了一个独立的二进制文件。)

Generally, it should be sufficient to set up the a credential helper once:

通常,设置一次凭证助手就足够了:

git config --global credential.helper wincred

Or instead of wincred, use whichever helper is appropriate for your platform. (If the name of the helper executable is git-credential-wincred, the value you set the option to will be wincred, etc.)

或者代替wincred,使用适合您平台的任何帮助程序。(如果 helper 可执行文件的名称是git-credential-wincred,则您将该选项设置的值将是wincred等)

The credential helpers also support the need to have separate sets of credentials for different repositories on the same host.

凭证助手还支持为同一主机上的不同存储库拥有不同的凭证集的需要。

回答by Kshitiz Sharma

Run this command inside your repo:

在您的存储库中运行此命令:

git config credential.helper store

Then push to the server once:

然后推送到服务器一次:

git push

The credentials you use to push to the server will get saved in ~/.git-credentials.

您用于推送到服务器的凭据将保存在~/.git-credentials.

Instructions taken from this guide here.

从本指南这里获取的说明。

回答by Oleg

Why can't you just use password in remote url?

为什么不能只在远程 url 中使用密码?

$ git config remote.origin.url = http://username:password@origin_link.com/repository.git