Jordan Smalls

Software Engineer

Count lines of code with Git

Get the line count of tracked files in a Git repository using the CLI.

Run this from the root of your repository. Git lists tracked files, while xargs passes them to wc to count their lines. Null-delimited paths keep filenames with spaces intact.

sh
git ls-files -z | xargs -0 wc -l

For a source-only count, filter the tracked paths by extension. This example includes TypeScript and TSX files. Counts include blank lines and comments, and missing working-tree files will produce errors.

sh
git ls-files -z -- '*.ts' '*.tsx' | xargs -0 wc -l