Find number of Lines of Code from GitHub Repository

Updated on January 4, 2022

How many lines of code did you write? Well, that was the question asked by one of the interviewers in my interview. At that time, I didn’t really know what to answer and I just blindly said it would be around ‘2 Lac lines of code’. Since the question was not for a particular project, I thought of giving a rough number considering my experience in coding for the last 17 years. The interviewer expressed his shock – that’s a big number. Interview over!

Later I was wondering whether that question really made any sense, because would anyone count the number of lines they had written. At least I had never done that before and I’m not sure doing it would be of any help. A quick search on Google helped me to understand the reason behind this question. Though few programmers felt such metric would not be of any help, few others felt it could be a good metric to estimate the skill of a programmer. Nevertheless, in this tutorial, I’ll be discussing how to find a number of lines of code from the GitHub repository.

Let us use the ‘jquery/jquery‘ repository for all the examples.

Using GLOC Chrome extension

GLOC extension for Chrome browser will give you the approximate count of lines of code in the GitHub repository. The extension can work for both the public and private repository, considering that you have a valid API token for private ones. Once the extension is installed, you can quickly generate the API token from GitHub. Click on the extension and settings gear at the top right corner to save the access token as shown in the below image.

GLOC extension

That’s it! Now go to GitHub and access any of the repository pages, user profile page to view the approximate line counts.

Number lines of code

GitHub LOC

Using an online tool from code tabs

Go to Codetabs.com and just input the GitHub repository URL and click the ‘ADD’ button to view the lines of code under various programming languages.

Count LOC online

Using tokei

Tokei is a simple program to display the statistics of your code. The program can show the number of files, lines, code, comments, and blanks grouped by the language. Come, let us install tokei and have a look at the stat.

On Centos 7:

yum install conda

conda create -n tokei

conda activate tokei

Install tokei using the below command.

conda install -c conda-forge tokei

Let us know clone the GitHub repository that you wish to read the statistics. For example, ‘jquery/jquery‘ repository.

git clone --depth 1 https://github.com/jquery/jquery.git
tokei jquery/

tokei loc

Using Sloc

You can install sloc from npm as shown below:

npm install sloc -g
git clone --depth 1 https://github.com/jquery/jquery.git
sloc "jquery" --format cli-table

Find number of Lines of Code

Well, that’s it! If you have any other tricks to find the number of lines of code, let us know in the comments. Also do let us know if you have faced this question ‘how many lines of code you had written” and how you handled it in the interview.

Was this article helpful?

Related Articles

Leave a Comment