OMBD#13: Find Out the Total Number of Lines on a Git Repository

Welcome to issue #13 of One Minute Better Developer, where you become a more successful software developer by reading short nuggets of knowledge, one minute at a time.

⏮️ 🔛 ⏭️

Art by my buddy Loor Nicolas


Our engineering manager has asked us about the total number of lines on several repositories of the company. How can we find out that information?


We are going to use the command git ls-files and pipe its output towc using xargs .

  1. As a repository example, we are going to create a new project using superplate.
npx superplate-cli my-app

2. Once created, we are going into the repo directory.

cd my-app

3. Now we can run git ls-files to recursively see all the files versioned in the repo.

git ls-files# .babelrc
# .eslintignore
# .eslintrc
# .gitattributes
# ...

4. However we want to also see the number of lines on every file. We are going to pipe the output of git ls-files to wc using xargs .

git ls-files | xargs wc#       1       4      30 .babelrc
# 1 2 26 .eslintignore
# 25 37 600 .eslintrc
# 1 2 12 .gitattributes
# ...
# 25891 49458 1219057 total

Here we see:

  • 1st column: number of lines in that file.
  • 2nd column: number of words in that file.
  • 3rd column: number of characters in that file.

And in the last row, information on the total of files.

So our repo has 25891 lines.

Full-Stack Developer, Teacher, Maker, and general Things-Doer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Docker Compose + GPU + TensorFlow = ❤️

Install WordPress in any VPS

The Commercial Scrum Conundrum

Life is a journey of twists and turns, peaks and valleys, mountains to climb and oceans to explore.

We are helping Parlia to map the world’s opinion

Understanding callbacks

Topic:- S3 bucket with versioning and life cycle policies and access S3 bucket with AWS IAM roles…

10 Best VSCode Extensions To Help You Code Like A Pro

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jon Portella

Jon Portella

Full-Stack Developer, Teacher, Maker, and general Things-Doer.

More from Medium

How to Receive Webhook Events With Netlify Functions and JavaScript

🎉 Launching King Cross Conversations, a video series about the web

TypeScript ‘xcopy exited with code 9009’ error solution