有什么办法可以防止git在Windows上打开密码提示框吗?

Is there a way to prevent git from opening a password prompt box on Windows?

在使用 git bash 推送远程存储库时,需要并询问我的密码。这不是问题。

问题是我习惯于在 git 控制台中输入密码,但后来我从 Linux 切换到 Windows 并在提示中询问我的密码盒子而不是控制台。

我发现它不太方便:我必须等待它出现一秒钟,有时我会失去焦点。

奇怪的是,如果我关闭对话框,然后会从 git 控制台询问密码。这就是我要找的。

你知道我怎样才能阻止提示框,让我在控制台中输入密码吗?我应该修改一些 git 选项吗?

如果您要将代码推送到您经常使用的存储库,我建议您使用 public 密钥而不是密码来验证自己。如果你这样做,你将不会被一遍又一遍地要求输入密码,无论是在控制台还是在提示符中都不会

这似乎与git-configcore.askPass选项有关。

文档说:

core.askPass
Some commands (e.g. svn and http interfaces) that interactively ask for a password can be told to use an external program given via the value of this variable. Can be overridden by the GIT_ASKPASS environment variable. If not set, fall back to the value of the SSH_ASKPASS environment variable or, failing that, a simple password prompt. The external program shall be given a suitable prompt as command-line argument and write the password on its STDOUT.


我的默认配置不包含有关此选项的任何内容,所以我猜它会退回到 "simple password prompt".

要覆盖此行为,我只需将选项设置为空字符串即可:

git config --global core.askPass ''

然后,在没有任何提示的情况下从控制台询问密码。

2022 年(6 年后),您可以安装 latest GCM 2.0.692(Git 凭据管理器)。
并将其用于:

  • git config --global credential.helper manager-core
  • git config --global credential.guiPrompt false
  • 或:SET GCM_GUI_PROMPT=0

这将禁用任何提示,只给用户留下一个终端提示。