如何自动将答案传递给命令行

how to automate to pass answer to commad line

正在尝试自动化我的 github 身份验证 每当我 运行 git push 它要求我输入用户名和身份验证

我想自动化它抛出脚本,这样每当它要求输入用户名时,我的脚本就会传递给它 注意:甚至 git 推送命令也是通过脚本自动执行的

以下是我如何使用脚本 git 自动推送

read -p "Do you want to push changes? (y/n)" push_choice 
if [ "$push_choice" == "y" ];
then
git push

它不止于此,但在代码点击 git 推送命令后,它要求我输入密码和用户名。

那么有没有什么方法可以让这个脚本传递它需要的所有信息,因为每次它都要求相同的用户名并传递

使用带有 public 密钥身份验证而不是密码的 SSH。

参见例如 https://docs.github.com/en/authentication/connecting-to-github-with-ssh/about-ssh