使用 git 推送时将 'terminal' 重定向到 'stdin'

Redirect 'terminal' to 'stdin' when pushing using git

有没有什么办法可以将 terminal 输入重定向到 stdin 如下所示?

$ git push origin master
Username for 'https://github.com':

然后我可以通过 stdin 传递我的 username/password。

例如,在基于 linux 的系统中,sudo 命令总是从终端读取密码,但如果您为其提供 -S 标志,那么它将从终端读取密码标准输入。

我很好奇 git 命令中是否有类似的标志?

注意:我的问题只是关于将 git 命令的输入重定向到标准输入,我不关心安全性或任何其他事情。

Git 通常不会询问自己的密码:它会在其他程序上关闭该工作。

当使用 ssh(git clone ssh://... 等)时,Git 直接运行 ssh 本身。这让一切都取决于 ssh。

使用 http 或 https 时,Git 使用 libcurl 库和 凭证助手 。您可以告诉 Git 使用哪个凭据助手,这样您就可以自己编写一个从标准输入读取密码的工具,然后告诉 Git 使用那个。这会很不安全,但你绝对可以做到。

其余部分,请参见Git push requires username and password