I would like to extract the information that is printed after a git status
, which looks like:
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
Of course I can parse the output of git status
but this is not recommended since this human readable output is liable to change.
There are two problems:
origin/branch
but need not be.git rev-list origin..HEAD
will show the commits that are in your current branch, but not origin -- i.e., whether you're ahead of origin and by which commits.
git rev-list HEAD..origin
will show the opposite.
If both commands show commits, then you have diverged branches.