Little Git Tricks: How many Commits are in a Branch?

Certain questions about a project can only be found in the source repository. The commit messages contain details on how your code was developed that you probably nowhere else have documented. The same is true if you want to know how many commits where made in a branch.

If you work with release branches (where all the bugfixes for a specific version go to a branch), then the number of commits is most likely the same as the number of bugfixes. The following command returns the number of commits in your current branch since you split it from master:

The rev-list option is used to work with the revision list. The option --count will only return a number while --no-merges ignores the merges when two or more people work together and don’t update their local copy before they commit.

The graph shows this scenario: commit B is the version you released. You then started with the branch v1.2 and created commits 1 through 3. You currently are on commit 3 and the above command will return 3. Commit C was in the master branch and will not be counted.

Git has many more commands that aren’t visible in most graphical user interfaces. Depending on the questions you have its worthwhile to leave the comfort of a graphical client and go down to the command line.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.