You may not be able to get GitHub to show you what you want, but it is easy enough in command-line Git. Just remember that the command line works on your repository, not on any repository over on GitHub, so you'll need to be sure to have your repository synchronized with the GitHub-side ones (via git fetch
and/or git push
as needed).
Suppose that you'd like to compare the name origin/feature-branch
(as seen in your Git repository, representing your Git's memory of origin
's feature-branch) to the name
upstream/branch-A(your Git's memory of
upstream's
branch-A`). You can do:
git rev-list --count upstream/branch-A..origin/feature-branch
The two-dot notation here means: Find commits that are reachable by starting with whichever commit origin/feature-branch
names, and look at those commits, but stop looking when you get to a commit reachable from upstream/branch-A
. You can use this construct with many Git commands, including git log
:
git log upstream/branch-A..origin/feature-branch
Here, we're using it with git rev-list
, which is a lot like git log
—they're kind of sister commands—except that rev-list
simply lists the commit hash IDs (this is intended for feeding to other Git programs). With the --count
option, instead of listing the hash IDs, it counts them. So this gives a count of commits that are reachable from origin/feature-branch
, but not reachable from upstream/branch-A
, and that's your "ahead of" count.
Additional information
There's also a count of commits reachable from upstream/branch-A
but not reachable from origin/feature-branch
. We can get this with:
git rev-list --count origin/feature-branch..upstream/branch-A
Note that the placement of the two names around the ..
special-character-sequence is swapped. Given what you've done recently, you can typically expect this count to be zero: that is, there are no such commits.
You can get both counts at once using git rev-list --left-right
and the three-dot syntax, upstream/branch-A...origin/feature-branch
for instance, but we'll leave that for later.
For (much) more on the concept of reachable commits, see Think Like (a) Git.