Question: 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 to commit.

```bash
git status
echo $?  #this is always 0

```

I have an idea but I think it is rather a bad idea.

```bash
if [ git status | grep -i -c "[a-z]"> 2 ];
then
 code for change...
else
  code for nothing change...
fi

```

any other way?

---

**update with following solve, see Mark Longair's post**

I tried this but it causes a problem.

```bash
if [ -z $(git status --porcelain) ];
then
    echo "IT IS CLEAN"
else
    echo "PLEASE COMMIT YOUR CHANGE FIRST!!!"
    echo git status
fi

```

I get the following error `[: ??: binary operator expected`

now, I am looking at the man and try the git diff.

===================code for my hope, and hope better answer======================

```bash
#if [ `git status | grep -i -c "$"` -lt 3 ];
# change to below code,although the above code is simple, but I think it is not strict logical
if [ `git diff --cached --exit-code HEAD^ > /dev/null && (git ls-files --other --exclude-standard --directory | grep -c -v '/$')` ];
then
        echo "PLEASE COMMIT YOUR CHANGE FIRST!!!"
    exit 1

else
    exit 0
fi

```

Answer: 
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 $$;

```
I'm using this in a script to have:

* 0 when everything is clean
* 1 when there is a diff or untracked files

[ -z "$(git status --porcelain)" ]