Skip to content

Instantly share code, notes, and snippets.

@mandiwise
Last active December 27, 2025 13:49
Show Gist options
  • Select an option

  • Save mandiwise/dc53cb9da00856d7cdbb to your computer and use it in GitHub Desktop.

Select an option

Save mandiwise/dc53cb9da00856d7cdbb to your computer and use it in GitHub Desktop.
A command to calculate lines of code in all tracked files in a Git repo
// Reference: http://stackoverflow.com/questions/4822471/count-number-of-lines-in-a-git-repository
$ git ls-files | xargs wc -l
@tomas-maciulis
Copy link

tomas-maciulis commented Jul 2, 2025

To only include the lines of code, can simply do

git ls-files "*.go" | xargs cat | grep -v '^\s*$' | grep -v '^\s*#' | wc -l

Just replace .go with your language's file extension. This excludes blank lines, configurations and comments so it presents an accurate number of actual lines of code.

@zadafiyaharsh2-ctrl
Copy link

zadafiyaharsh2-ctrl commented Dec 25, 2025

nstall cloc
choco install cloc
then
cd repo-name
then
cloc .

@andyg2
Copy link

andyg2 commented Dec 27, 2025

Install cloc choco install cloc then cd repo-name then cloc .

Repo https://github.com/AlDanial/cloc GPL-2.0 / 22k stars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment