The OP's question is more than 9 years old now. I don't know what man git-status
said then, but here's what it says now:
--porcelain[=<version>]
Give the output in an easy-to-parse format for scripts. This is similar to the
short output, but will remain stable across Git versions and regardless of user
configuration. See below for details.
The version parameter is used to specify the format version. This is optional and
defaults to the original version v1 format.
This suggests that the --porcelain
argument is well-suited to testing the status of a repo for changes.
Wrt the OP's question, "Is there some kind of boolean check if there has been changes since the last commit, or how can I really test if there are new changes to my local repository?"
I don't think that bash
has boolean data types per se, but this may be close enough:
[ -z "`git status --porcelain`" ] && echo "NULL-NO DIFFS" || echo "DIFFS EXIST"
This can be re-cast as a if-then-else
form for a script, or executed as-is fm the CLI while in the git repo folder. Otherwise, use the -C
option with a path spec to the repo of interest:
git -C ~/path/to/MyGitRepo status --porcelain
Addendum:
- Some advise using the
-u, --untracked-file
option to avoid reporting status on files one wishes to ignore. Note this comes with an unfortunate side-effect: files that are newly added are not statused either. The option is useful in some situations, but consider it carefully before using.
git status
?