The goal is to get an unambiguous status that can be evaluated in a shell command.
I tried git status but it always returns 0, even if there are items
If you are like me, you want to know if there are:
1) changes to existing files 2) newly added files 3) deleted files
and specifically do not want to know about 4) untracked files.
This should do it:
git status --untracked-files=no --porcelain
Here's my bash code to exit the script if the repo is clean. It uses the short version of the untracked files option:
[[ -z $(git status -uno --porcelain) ]] && echo "this branch is clean, no need to push..." && kill -SIGINT $$;