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

Git

Git Problem Overview


How would you get a count of all the files currently in a git repository?

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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

Solution 3 - Git

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...

Solution 4 - Git

This is a solution for Windows using PowerShell

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

Solution 5 - Git

In the github repository view there is no way, you can clone or download the project and use an external tool.

If you are comfortable with command-line tools, you can install git-sizer and run it against a repository you have cloned locally. It can tell you more about your repository than you ever wanted to know.

Check out tokei and git-sizer.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDan RigbyView Question on Stackoverflow
Solution 1 - GitDan RigbyView Answer on Stackoverflow
Solution 2 - Gituser40176View Answer on Stackoverflow
Solution 3 - GitBen WindingView Answer on Stackoverflow
Solution 4 - GitTellonView Answer on Stackoverflow
Solution 5 - GitAbu Noman Md SakibView Answer on Stackoverflow