Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

Count All Git Commits in a Repo

count-all-git-commits-in-a-repo.jpg

This could be useful to compare activity across multiple repos.

Quick Jump:

A while back I wrote a detailed guide on using git shortlog to count commits for specific authors but this time around we’re going to focus on only getting the number of total commits.

Here’s a couple of examples:

# All branches.
git rev-list --count --all

# Currently checked out branch.
git rev-list --count HEAD

# Skip merge commits.
git rev-list --count HEAD --no-merges

# Only merge commits.
git rev-list --count HEAD --merges

There’s quite a lot of other flags you can use such as --since and --before to limit counts by date, --author to limit by author and more. I covered these flags in the shortlog post, they happen to apply to rev-list too.

When would you consider using these commands?

Here’s a couple of personal use cases that came up recently:

  • I wanted to quickly see how many commits I’ve added to my assorted Docker web app example apps to see how much time I’ve been spending on them relative to each other
  • A client had a number of services they’ve built over the years and we wanted to get an idea where devs were spending their time, using --since here was useful to get recent vs lifetime stats

# Demo Video

Timestamps

  • 0:05 – A few examples
  • 0:52 – Personal use case with my Docker example apps
  • 1:54 – Figuring out which service developers are spending time on

When was the last time you used this command? Let us know below!

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments