I found this answer already: Number of commits on branch in git
but that assumes that the branch was created from master.
How can I count the number of commits along a branch without relying on that assumption?
In SVN this is trivial, but for some reason is really difficult to figure out in git.
To count the commits for the branch you are on:
for a branch
If you want to count the commits on a branch that are made since you created the branch
This will count all commits ever made that are not on the branch-name as well.
Examples
Result: 3
If your branch comes of a branch called
develop:Result: 3
Ignoring Merges
If you merge another branch into the current branch without fast forward and you do the above, the merge is also counted. This is because for git a merge is a commit.
If you don’t want to count these commits add
--no-merges: