I need to check whether a git push
command would actually push something in a bash script. I cannot work with exit codes because it is zero for both a successful push and the "no push necessary"-case.
This is my current workaround, but it's probably not very elegant.
# some code that does things with a repo
# check whether push is necessary
push_output=$(git push origin "$BRANCH" --dry-run 2>&1)
if [[ "$push_output" == "Everything up-to-date" ]]; then
echo "no push necessary."
# do something
else
# do something else
fi
# more code here