Git Windows 禁用密码提示 UI 但从 shell 获取密码提示

Git Windows Disable password prompt UI but get password prompt from shell

在 git bash for windows 中,在单独的 UI 弹出提示中询问用户名 and/or 密码,如下所示。

点击取消时,您会得到以下基于 shell 的提示,其中可以输入相同的用户名。

有什么方法可以禁用这些提示吗? 我仍然想输入我的用户名和密码,但是我想通过基于 shell 的提示而不是基于 UI 的提示输入它。

使用这里的建议没有帮助。

使用 ssh 代替 http/https。

您需要在您的本地机器上设置 ssh 密钥,将它们上传到您的 git 服务器并将 url 形式 http:// 替换为 git:// 然后您将不再需要使用密码。

如果您不能使用 ssh,请将此添加到您的配置中:

[credential "https://example.com"]
    username = me

文件是here

尝试全局设置变量 core.askPass(在您的配置文件中)

$ git config --global core.askPass true

或使用 -c 开关仅针对一个命令覆盖它

$ git -c core.askPass=true clone <https_url>

参见:https://git-scm.com/docs/gitcredentials

If a helper outputs a quit attribute with a value of true or 1, no further helpers will be consulted, nor will the user be prompted (if no credential has been provided, the operation will then fail).

注意:使用 git config --global --unset core.askPass 取消设置 core.askPass 没有帮助。它需要像上面那样设置为 true

2021-10-22 更新:

最初的答案建议设置空字符串 "",但至少在 Ubuntu 这不起作用,文档还描述了帮助程序应该输出 true1.

取消设置 SSH_ASKPASS

unset SSH_ASKPASS

要在每次打开 git bash 时自动执行此操作,您可以将以上行添加到 .bashrc.

的末尾

调查

The gitcredentials docs 链接在其他答案列表中的许多地方 git 将检查以确定如何询问密码。我依次调查了每一个:

env | grep GIT
git config --get core.askPass
env | grep SSH

最后一条命令告诉我 SSH_ASKPASS 存在:

SSH_ASKPASS=/mingw64/libexec/git-core/git-gui--askpass`.

这不是我的点文件的一部分,因此似乎来自 http://git-scm.com.

的默认 Windows git 分布

您可以试试下面的配置:

git config --global --unset credential.helper

git config --system --unset credential.helper

当我在 Windows 7.

上使用 PortableGit 64 位 2.12.1.1 时,这对我很有帮助

就我而言,我已经使用 git 1.9.5 3 年了。 最近我尝试安装最新版本 2.15.0。 在最新的 git bash 中,当我执行 git pull 时,它要求我输入密码,而在旧的 git 版本(1.9.5)中,它不会询问类似那。

我确实在 google 中搜索过。最后我的朋友帮我解决了这个问题。 这是因为我配置了 dsa 密钥而不是 rsa 密钥。 根据我的理解,dsa 是旧密钥格式,rsa 是新密钥格式。

为了使用最新的 git bash 和旧的 dsa 密钥,我做了下面的事情, 在 .ssh 文件夹中创建一个名为 "config"(这是全名)的文件。 在该文件中给出以下注释,

PubkeyAcceptedKeyTypes=+ssh-dss

并保存。

现在打开最新的gitbash。并做 git 拉。它不会询问任何密码,只会提取提交。