DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for See how much you coded in the past year with git!
Austin Blade
Austin Blade

Posted on

See how much you coded in the past year with git!

2020 is almost over. (INSERT JOKE ABOUT HOW CRAPPY 2020 WAS FOR MOST PEOPLE HERE). Regardless of the year, I like to give myself an "annual review" every year. Part of that review is to see how much I coded in the past year. Not only is this just fun, but it could also give you some weight in your argument for a promotion or pay raise at your next review. πŸ€‘

If you've used GitHub, you've probably seen their contribution calendar that looks something like this.

GitHub Contributions

That's fine and dandy, but what if you aren't using GitHub? What if you want more info that could compare your performance to a team? All that and more will be discussed right after this quick commercial break!

Old Phone Commercial

Alright, let's get to business. This walk-through will work for ANY codebase that uses git for version control. My company uses Azure, so I don't get the nifty contribution calendar by default.

We will be using an npm package called "git-stats".

git status logo

First, open up your terminal and install git-stats globally using:

npm i -g git-stats
Enter fullscreen mode Exit fullscreen mode

Git stats will now keep track of your commits for future reference, but there's currently no data for it to work with. We need to install another tool to import all of our commits from the repository into git-stats.

The tool we need is called "git-stats-importer". We can install it globally using:

npm install -g git-stats-importer
Enter fullscreen mode Exit fullscreen mode

After "git-stats-importer" is installed, cd into the repository you want stats for.

cd path/to/my-repository
Enter fullscreen mode Exit fullscreen mode

Then run:

git-stats-importer
Enter fullscreen mode Exit fullscreen mode

If you get an error that says "Cannot find any emails", like this

Can't Find Emails Error

you will need to run the command again followed by a "-e" and the email you use to access the repository like so:

git-stats-importer -e youremail@joinhandshake.com
Enter fullscreen mode Exit fullscreen mode

After running that command you should see a bunch of import lines followed by an "info Done."

At this point, we have everything we need to check out our stats!

To see a contribution calendar (similar to GitHub's) in your terminal, type this command:

git-stats
Enter fullscreen mode Exit fullscreen mode

You'll see all of your contributions from the past year in the same format!

git stats results

If you wanted to see all of the contributions for your entire team (instead of those from just yourself) you can run:

git-stats -g
Enter fullscreen mode Exit fullscreen mode

And finally, to see how you stand compared to the rest of your team with contributions, you can generate a pie chart in your terminal with the percentages of contributions by each author in the repository by running:

git-stats --authors
Enter fullscreen mode Exit fullscreen mode

The result should be something similar to this!

git status pie chart

How cool is that?! I like to keep track of how I'm doing and compare it year to year. Hopefully this can help you measure your goals and progress over the past year. πŸ™‚

Top comments (17)

Collapse
madza profile image
Madza

When you do git-stats --last-decade πŸ˜‚πŸ˜‚

IMG

Collapse
austinblade profile image
Austin Blade Author

bahaha now that’s some β€œclean code” πŸ˜‚ *sorry attempt at a shower pun..πŸ™ƒ

Collapse
madza profile image
Madza

To extend your pun, they prolly formatted each commit like this:

Short and clear, thank you for this article!
I tend to use emojis for the type - it shows the type of the commit at first glance, e.g.:

βž• :heavy_plus_sign: when adding a file or implementing a feature
πŸ”¨ :hammer: when fixing a bug or issue
πŸ’š :green_heart: when improving code or comments
⚑ :zap: when improving performance
πŸ“œ :scroll: when updating docs or readme
πŸ”‘ :key: when dealing with security
πŸ” :repeat: when updating dependencies or data
βœ… :white_check_mark: when a new release was built
πŸ‘• :shirt: when refactoring or removing linter warnings
❌ :x: when removing code or files

... and looks awesome in the commit history:

Collapse
navthenugget profile image
Nav Pahwa

This comment has more hearts than the actual post πŸ˜‚

Collapse
hunterpp profile image
Hunter Peress

πŸ˜‚πŸ€£πŸ˜‚πŸ€£πŸ˜‚πŸ€£πŸ˜‚

Collapse
elmuerte profile image
Michiel Hendriks

No amount of data from git repositories gives an indication of my productivity or software development activity.

This contribution was more that 2 weeks of work. Yes, I switched 2 lines of code. I spend two weeks digging through our code, Spring Framework, and Hibernate to figure out what was going wrong in our product. This small, obscure, and quite old bug in hibernate, prevented me from upgrading from Hibernate 3 to 5, as our software would not work 50% of the time.

The value software developers add is done by solving problems, not by producing newlines, commit records, or any other quantitative metric.

Collapse
djquecke profile image
DJ Quecke

In some circumstances you have the producers of the code and a separate entity as a fixer.

I spent a large portion of my career on a fixer crew and you're right that line count or any other metric is pretty useless. The less they heard from us, the better everyone was doing.

All that said, I suspect some guys just produce code and there are several metrics for them. But, even for them, line count isn't a helpful metric. If you measure folks by line count, you'll end up with bloated code.

I think as Austin points out though, this is a self-review, and could be useful as a self-metric. Always remembering that short, concise code will usually compile and run more efficiently.

Collapse
austinblade profile image
Austin Blade Author

You’re 100% right. Developers are worth more than their commit records. It’s nearly impossible to accurately measure a dev’s value. Some leads spend most of their time thinking through design patterns to implement. That doesn’t mean the person who comes in and implements that design pattern contributed more than the lead. That said, you need something to help support your argument during a business review. This isn’t something to rely on exclusively, but it can help prove you weren’t scratching your ass all day instead of coding. Keeping a journal to reference big things that you contributed is the best way to reflect on your work.

Collapse
choroba profile image
E. Choroba

Neat! I need to extend my git-graphs, they only draw the commits per month/week/day, added/deleted lines, and commits per hour and weekday.

Collapse
stefango profile image
stefango • Edited on

This works fine in Win10 CMD, but errors below will appear in git-bash:

$ git-stats
C:\Users\Administrator\AppData\Roaming\npm\node_modules\git-stats\node_modules\cli-gh-cal\lib\index.js:53
    var CLI_COLUMNS = require('window-size').width;
                                            ^

TypeError: Cannot read property 'width' of undefined
    at CliGhCal (C:\Users\Administrator\AppData\Roaming\npm\node_modules\git-stats\node_modules\cli-gh-cal\lib\index.js:53:45)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\git-stats\lib\index.js:512:24
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\git-stats\lib\index.js:413:9
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\git-stats\lib\index.js:314:9
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\git-stats\node_modules\r-json\lib\index.js:23:13
    at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
Enter fullscreen mode Exit fullscreen mode
Collapse
austinblade profile image
Austin Blade Author

Hmmm that’s interesting. I ran it in bash fine. I’d have to look at the source code to figure out what’s going on.

Collapse
gizmotronn profile image
Liam Arbuckle

Nice job, definitely going to use this. I've mainly used Github for the past 24 months and I've got a 640 day streak there :)

Collapse
austinblade profile image
Austin Blade Author

Wow! Congrats on the super long streak! That’s impressive!

Collapse
gklijs profile image
Gerard Klijs

Nice, would it be easy to make it use al the git repo's in a certain folder? We currently have something like 50 repo's..

Collapse
austinblade profile image
Austin Blade Author

I don’t think the method from the article would work for multiple repo’s.. If you’re using GitHub or BitBucket, you can get all of the info you need from all of your repo’s with this tool github.com/IonicaBizau/repository-.... I’m unaware of any other tools to help consolidate all of that data.

Collapse
gklijs profile image
Gerard Klijs

Thanks, it's on gitlab, but don't really need it. Would be nice to be able to combine 'all' through.

Collapse
moopet profile image
Ben Sinclair

As with most node packages, this crashes for me before it even gets to importing anything.

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.