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
It's possible to combine git status --porcelain
with a simple grep
to perform the test.
if git status --porcelain | grep .; then
echo Repo is dirty
else
echo Repo is clean
fi
I use this as a simple one-liner sometimes:
# pull from origin if our repo is clean
git status --porcelain | grep . || git pull origin master
Add -qs
to your grep command to make it silent.