After git fetch , to check if there are local commits in your branch that were not pushed to the remote, try the following:
git diff --exit-code <remote>/<branch>..<branch>
It will also tell you if there are commits on the remote computer that you do not have on the local computer. Please note that this is just a change check, so if there were different commits with identical changes in the remote and local branch, this command might not detect this. In a script, I usually associate this with /dev/null and just check the return status. So, if your remote is origin and your master branch, the command will look like this:
git diff --exit-code origin/master..master > /dev/null
Like others, I also use git diff --exit-code and git diff --cached --exit-code to check for local uncommitted changes.
source share