git pull while ssh into remote 显示 username/password 没有提示

git pull while ssh into remote shows no prompts for username/password

我正在尝试编写一个脚本,通过 ssh 连接到远程位置,然后按如下方式执行 git pull

ssh url@location << EOF
--other commands--
git pull
--other commands--
EOF

然而,每当我 运行 脚本时,它都会失败 username/password 提示,它永远不会在终端上显示。实际上,在这种情况下,我 更喜欢 必须输入我的凭据而不是对远程计算机进行调整,有人知道如何让提示出现吗?

您需要使用个人访问令牌在远程计算机上配置您的 git 用户,以免收到 username/password 提示。

你不需要这里的文档,你可以 write the command as ssh argument:

ssh url@location git pull

这不允许 git 询问密码,因为这是仅命令行调用,并且 git 需要终端询问密码。所以你必须让 ssh 分配一个伪终端:

ssh -t url@location git pull

如果您有多个命令 运行 — 将它们全部用引号引起来:

ssh url@location "cd /path/to/repo && git pull && echo ok"
ssh -t url@location "cd /path/to/repo && git pull && echo ok"