The help of "git status" does actually show the option you can use:
-b
--branch
Show the branch and tracking info even in short-format.
The format is different in --short
mode, but it's there:
$ git status --short --branch
## master...origin/heads/master [ahead 2]
[...] ^^^^^^^^^
If you don't care about the output format, git status --short --branch
internally runs the equivalent of git rev-list --left-right @...@^{upstream}
and interprets its results. You can run git rev-list
directly. It will give output if and only if your current branch and your remote branch are different, by giving you the commits that are in your current branch but not in your remote branch (ahead), as well as commits that are in your remote branch but not in your current branch (behind), in a diff
-style format.
Ahead:
$ git rev-list --left-right @...@{upstream}
<baa782ec4590a91d9835c36ad33f7681e4a859d5
<8b6255249bc08e2f14d8b6f31bab83b9c48cb698
Behind:
$ git rev-list --left-right @...@{upstream}
>0e0140fbf6f903aa7205063eac5b8cf6e268ab3b
Both:
$ git rev-list --left-right @...@{upstream}
<a7992ac7127b37d24b00fbecf67156688285be15
>0e0140fbf6f903aa7205063eac5b8cf6e268ab3b
You can optionally use git log
instead of git rev-list
and use its regular format options (such as --oneline
) to tailor the output format to your liking.
Or you can change the --left-right @...@{upstream}
to just @{upstream}..@
if you don't care about incoming changes, only about unpushed changes.