Find the Number of Lines in a Git Repository

Want to figure out how many lines of code are in your Git repository? I’ve had an alias in my .bashrc file for ages that does just that.

[bash]git ls-files | xargs wc -l[/bash]

It uses git ls-files to generate a list of files, which it then passes it to the wc command, which generates word and character count statistics (the “l” flag makes it count lines).

Obviously the line is a bit of a mouthful (handful?). So you can create an easier alias, like “gitlines” and put it in your .bashrc file.

[bash]alias gitlines="git ls-files | xargs wc -l"[/bash]