Following worked for me:
if [[ -n $(git status --porcelain) ]]; then echo "Changes detected. Preparing to commit and push." else echo "No changes to commit." fi
This is mentioned in detail here: What does the term "porcelain" mean in Git?