This question appears to be a duplicate of another question here on SO.
I'm adding this answer b/c I feel that most of the answers here are (either) wrong/out-dated or too complicated. And strictly as an opinion, I'll opine that the authors/maintainers of git
are suffering from something similar to what US President Joe Biden has! IOW, the fact that you cannot get a straight answer from git status
spells dysfunction in git-world.
That said, my simplified answer to the Question "Check if pull needed in Git" is this:
## cd to git repo; e.g.
$ cd ~/blockhead.git
$ git pull --dry-run # alternatively: 'git fetch --dry-run'
...
From thegitremote:/home/joe/git-srv/blockhead.git
2acea0b..b797bb0 master -> origin/master # <=== THIS MEANS A CHANGE HAS BEEN MADE
IOW: If there is a diff between the local and remote repos, it will be expressed in the output of git pull --dry-run
(similar to that shown above). If there is no diff the output will be null
.