简体   繁体   English

Git fetch命令在命令行成功,但在bash脚本中失败

[英]Git fetch command succeeds at command line but fails in bash script

git fetch someremote  # the remote is on github.com, and using SSH

the above command succeeds if I issue it from a terminal, but if I put it in a bash script, it will fail, with: 如果我从终端发出上述命令,则该命令成功,但是如果将其放入bash脚本中,它将失败,并显示:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I hope this gives someone some clue as to help figure out why it fails in the bash script but succeeds at a terminal! 我希望这能给某人一些线索,以帮助弄清为什么它在bash脚本中失败,但在终端成功! Anyone have any idea? 有人知道吗

Same thing seems to happen if I use either SSH or HTTPS 如果我使用SSH或HTTPS,似乎也会发生同样的事情

Probably a problem with your environment variables. 您的环境变量可能有问题。 Why not try diff ing them? 为什么不尝试diff它们呢?

$ echo "printenv | sort > /tmp/script.env" > /tmp/envtest.sh
$ bash /tmp/envtest.sh
$ printenv | sort > /tmp/term.env
$ diff /tmp/term.env /tmp/script.env

In my terminal I get: 在我的终端中,我得到:

76c76
< SHLVL=1
---
> SHLVL=2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM