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