List the contributors in a git repository

January 29, 2021 • 2 min read

Ever wondered what statistics you can get out of your git repository? Or who else has contributed to the project you're working on. Maybe you plan to keep track of the commits your team does and would like some kind of leaderboard for your repository. You secretly know that the amount of commits isn't a quantitative measure, but don't let it spoil your fun.

Git comes with a command, multiple actually, that can help you list the contributors of your repository. First off, let's take a look at the shortlog command which summarizes the output of the normal log command.

(~/django) $ git shortlog -ns
  3283  Tim Graham
  2802  Adrian Holovaty
  1872  Malcolm Tredinnick
  1740  Russell Keith-Magee
  ...

The two flags, -n and -s, are short options for --numbered and --summary respectively. The --numbered option sorts the output according to the number of commits per author instead of author alphabetic order. Where --summary suppresses the commit description to provide a commit count per author only.

This command does stay limited to the commits in the current branch however. You can pass the -all option to this command to include all git refs.

Filter committers by date

Seeing that commit count of 3283 by Tim does discourage me a bit (having that commit leaderbord in mind still). To be a bit more fair, you can include a starting date.

(~/django) $ git shortlog -ns --since=2021-01-01
    46  Mariusz Felisiak
     8  Hasan Ramezani
     5  Carlton Gibson
     5  Tim Graham
     ...

By listing the commits since first of january it looks like you have a shot now!

Make it a git alias

Planning on doing this more often? You can easily add it to the alias section of your git config file.

[alias]
  committers = shortlog -ns

Now it is as easy as running git committers.