I have a script (called update_content.sh
) that is supposed to run 3 consecutive git
commands and the first version looked like this:
#!/bin/sh
git fetch --all && git reset --hard && git merge
When I run it I see this output:
web@bane:~# ./update_content.sh
Fetching origin
error: unable to create file locales/fr.json (File exists)
error: unable to create file locales/it.json (File exists)
fatal: Could not reset index file to revision 'HEAD'.
However when I changed it to this:
#!/bin/sh
git fetch --all
git reset --hard
git merge
And run it I see this:
web@bane:~# ./update_content.sh
Fetching origin
HEAD is now at 5859b2e Added Business tab
Already up-to-date.
The newline approach gets the result I want however it does not have the "don't proceed if a step failed" quality of the &&
. Is there something about how git
works that makes it incompatible with the &&
or am I missing something about &&
?
I did a little more digging and found that the one liner with &&
when run from the command line doesn't throw errors but also doesn't actually reset the local working copy, however the new line approach inside a script (and run one at a time) does.