简体   繁体   中英

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:

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! Anyone have any idea?

Same thing seems to happen if I use either SSH or HTTPS

Probably a problem with your environment variables. Why not try diff ing them?

$ 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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