Join my Laravel for REST API's course on Udemy 👀

Get the total amount of git commits via the command line

May 4, 2021  ‐ 1 min read

When you browse GitHub repositories you nicely see some statistics about the repository including the total amount of commits made for a branch. This may give an indication on how actively a project is or was, this is definitely not always the case.

You can get this total number of commits locally via the command line as well. You can get this number via the rev-list subcommand.

In order to get the total commits count of your currently active branch you may use HEAD combined with the --count flag.

$ git rev-list HEAD --count

Instead of HEAD you can specify a branch name as well, whether it is your current branch or another one like main in the example below.

$ git rev-list main --count

And it works with remotes as well. Keep in mind however that you may need to fetch first before you see the correct number.

$ git rev-list origin/main --count

If you would like to get the count of unique commits on all branches combined you use the --all flag instead of the branch name.

$ git rev-list --all --count