Ranking engineers by commits and lines of code with Git and Bash

Commit counts and lines of code are the easiest engineering metrics to compute: Git already records who changed what, and a few lines of Bash turn that history into a ranking. This post shows four scripts that do it.
Be clear about what the numbers mean before you use them. They measure activity, not value. They’re cheap and repeatable, but they’re easy to game (split commits, reformat files, commit generated code) and they penalise work that removes code or happens outside the repository: reviews, design, debugging, mentoring. Use them as a conversation starter alongside code quality, bug fixing and collaboration, not as a score.
Files each author changed most, by extension
Section titled “Files each author changed most, by extension”#!/usr/bin/env bash# Usage: ./files_by_author.sh /path/to/repositorycd "${1:-.}" || exit 1
# File extensions to report onEXTENSIONS=("html" "scss" "tsx" "ts")
git log --format='%ae' | sort -u | while read -r author; do for extension in "${EXTENSIONS[@]}"; do echo "Changes made by $author to .$extension files:" git log --no-merges --fixed-strings --author="$author" --name-only --pretty=format: \ | grep "\.$extension$" | sort | uniq -c | sort -rn | head -n 10 donedoneFor each author email in the history and each extension, this lists the 10 files that author touched in the most commits:
git log --format='%ae' | sort -ulists every distinct author email.--authormatches against the author’s name and email;--fixed-stringsstops characters like.and+in an email being read as a regex.--name-only --pretty=format:prints only the changed file paths for each commit, and--no-mergesskips merge commits, which would otherwise repeat files.grepkeeps paths with the current extension,sort | uniq -ccounts how many commits touched each file, andsort -rn | head -n 10keeps the top 10.
Commits per author
Section titled “Commits per author”#!/usr/bin/env bashcd "${1:-.}" || exit 1
git shortlog -s -n --no-merges --all | while read -r count author; do echo "$author: $count"donegit shortlog groups commits by author. -s prints only the count, -n sorts by count (highest first), and --all counts commits reachable from every branch and tag, each commit once. Without a revision such as --all or HEAD, git shortlog reads a log from standard input when it isn’t run in a terminal, so keep one in scripts. Add -e to show email addresses if two people share a name.
Lines added and removed per author
Section titled “Lines added and removed per author”#!/usr/bin/env bashcd "${1:-.}" || exit 1
git log --no-merges --numstat --format='@%aN' \ | awk '/^@/ { author = substr($0, 2); next } $1 ~ /^[0-9]+$/ { added[author] += $1; removed[author] += $2 } END { for (a in added) printf "%d\t%d\t%s\n", added[a], removed[a], a }' \ | sort -rn--numstat prints added<TAB>removed<TAB>path for each file in each commit, and the @%aN format line marks which author the following numbers belong to. Binary files show - instead of numbers and are skipped. The output columns are lines added, lines removed and author name, sorted by lines added.
Lines each author owns today
Section titled “Lines each author owns today”#!/usr/bin/env bashcd "${1:-.}" || exit 1
git ls-files -z | xargs -0 -n1 git blame --line-porcelain 2>/dev/null \ | sed -n 's/^author //p' | sort | uniq -c | sort -rn \ | while read -r count author; do echo "$author: $count" doneThis counts the lines in the current checkout that git blame attributes to each author, so it measures code that survived rather than code written:
git ls-files -z | xargs -0 -n1passes each tracked file togit blameone at a time; the NUL separators keep file names with spaces intact.--line-porcelainrepeats the full commit header for every line, including anauthor <name>line, whichsedextracts.2>/dev/nullhides errors from pathsgit blamecan’t annotate, such as submodules.
It runs git blame once per file, so expect it to be slow on large repositories. Restrict it to source files with a pathspec, for example git ls-files -z -- '*.ts' '*.tsx'.
Gotchas
Section titled “Gotchas”- The same person often commits under several names or emails (work laptop, GitHub web UI). Add a
.mailmapfile to merge them;git shortlog,%aNandgit blamerespect it. - Bots, formatters, lockfiles and vendored or generated code inflate line counts. Exclude them with pathspecs such as
':!package-lock.json'or by filtering author names. - Commit counts depend on the merge strategy: a squash merge turns a pull request of many commits into one, so teams that squash and teams that don’t can’t be compared by commit count.
© 2026 David Li · Home · Blog · RSS ·Classic site · Built with Astro, Starlight and three.js · Logos:Font Awesome Free (CC BY 4.0)