I'm developing a git plug-in, and I need to know when a local repo is changed (can commit changes), ahead (can push to remote) or behind (can pull from remote) using the command line.
This is what I am doing so far:
- Can commit? - If - git diff-index --name-only --ignore-submodules HEAD --returns something, then yes, there are changes to commit.
- Can push? - If - git status -sbcontains the word ahead in it's output, then yes, there are commits to push.
- Can pull? - Nothing implemented yet. 
The can commit? part seems to work properly. Can push? only works for the master branch, and this is a huge problem.
How can I safely check if, on every branch, a git repo has changes to commit, commits to push, or needs a git pull?
 
     
     
     
     
    