Ram Rachum Ram Rachum - 11 days ago 5
Git Question

Git: Check programmatically if anything is staged

For a Git script I'm writing, I'd like to have a programmatic way to check whether there is anything at all staged. i.e. I want a positive result if anything at all is staged, and negative if nothing is staged.

Bonus points: A way to programmatically check whether there is anything new in the working tree that can be staged.

Answer

You're looking for:

git diff --cached --quiet

(or replace --quiet with --exit-code if you still want output)