How to get a count of all the files in a git repository?

You can get a count of all tracked files in a git respository by using the following command:

git ls-files | wc -l

Command Breakdown:

  • The git ls-files command by itself prints out a list of all the tracked files in the repository, one per line.
  • The | operator funnels the output from the preceding command into the command following the pipe.
  • The wc -l command calls the word count (wc) program. Passing the -l flag asks it to return the total number of lines.

Note: This returns a count of only the tracked files in the repository meaning that any ignored files or new & uncommitted files will not be counted.


Just to build on the accepted answer, you can also filter which types of files you want to count.

Count only .json files

# Will output only json file paths
git ls-files "./*.json" | wc -l

Count only .c files

git ls-files "./*.c" | wc -l

A fairly useful way to gauge what languages are common in a repo...


If you came here looking for a way to do this for a repo hosted on github without cloning it, you can do this:

svn ls -R https://github.com/exampleproject/branches/master | wc -l

This is a solution for Windows using PowerShell

git ls-files | %{ Get-Content -Path $_ } | measure

Tags:

Git