1 min read

Count Lines of Git Repository

If you are interested in determining the number of lines of code written in your GIT project, the following bash snippet can prove to be quite useful.

git log --numstat --format="" "$@" \
    | awk '{files += 1}{ins += $1}{del += $2} END{print "total: "files" files, "ins" insertions(+) "del" deletions(-)"}'

Save this script as git-summary in your system path. GIT will automatically recognize it as a subcommand, enabling you to use git summary without configuring an alias in your GIT settings.

Dont forget to execute chmod +x /your/path/git-summary{bash} to make it executable.

Here is a sample output:

$ git summary --all
total: 2465 files, 107799 insertions(+) 12092 deletions(-)

You can also apply filters based on time, author, branch, and more:

git summary --author=fer
git summary main..develop
git summary --author=fer main..develop
git summary --all
git summary --since=yesterday
git summary --since=2023-03-08

Reference: https://stackoverflow.com/a/61945239/302974