How to use git blame effectively
Tags: git, programming, tutorial, beginners
Published: 2020-06-26 13:53:25

---
title: How to use git blame effectively
published: true
tags: git, programming, tutorial, beginners
canonical_url: https://gitbetter.substack.com/p/how-to-use-git-blame-effectively
---

![](https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fe938315d-640c-4521-b892-5cedbbabe2dd_500x310.gif)

> #### This post was originally posted in the newsletter [GitBetter](https://gitbetter.substack.com/). If you are interested in leveling up your game in Git, you can subscribe to it.

Git blame is used to see the last commit and the last author who has modified for each line in the file.

In other words, using git blame, you can see the entire git revision of the file with respect to each line.

Git blame will come in handy when you want to which commit is responsible for the changes and which author has committed those changes.

**Usage**

```
git blame <file_name>
```
![](https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F1a85f8b6-b4e0-47ce-8a3e-8eea58a95f85_954x277.png)

In the above example, I have blamed for a file. You can see the short commit hash, author name, and timestamp for each line throughout the file.

#### Blaming only a limited line range

Sometimes, You don’t need to blame the entire file, you just need to blame in a limited line range. Git blame provides the option for that.

**-L** will take the option for the start line and for the end line.

```
git blame <file_name> -L 80,100
```

The above command will blame from line 80 through line 100.

![](https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F6599c307-5f37-4ca7-b186-561e5426ac77_947x457.png)

In the above example, see the starting line and the ending line.

#### Blaming by commit timestamp

You can also blame by commit timestamp

```
git blame <file_name> --since=3.days
```

This command will blame commits that are more than 3 days old.

#### Blame in Github and in Gitlab

There is an option to blame in Github and in Gitlab.

If you click on any file in Github you can see the blame option.

![](https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2Fb942b32b-5ba8-436f-970a-92fe92bd12da_1171x295.png)

Using that option, you can see the entire git revision of that file.

Below is an example of blame in Github.

![](https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F3b7ff60c-7129-4b37-8d82-8bfd9700f677_1267x533.png)

Git blame is a very effective tool that helps you to learn the entire git history of the file line by line.

And this also helps you to figure out which of your peers made that breaking change in the production so that you can blame them :P Just kidding don’t do that :)

Git blame is mostly used with some GUI tools. Because git blame in raw mode is not very readable.

There are also extensions in code editors like Sublime, VS Code you can configure.

**Sublime -** You can try [Git blame extension](https://packagecontrol.io/packages/Git%20blame)

**VS Code -** You can try [Git lens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens)

Apart from these extensions, there is also another nicer way of viewing the blame. You can use **Git GUI** tool. It comes pre-installed with Git and it works with popular platforms.

```
git gui blame <file_name>
```

![](https://cdn.substack.com/image/fetch/w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fbucketeer-e05bbc84-baa3-437e-9518-adb32be77984.s3.amazonaws.com%2Fpublic%2Fimages%2F4b4e9618-d948-41c7-8174-94464db5386a_989x487.png)

Apart from blaming, Git GUI also has other options. You can explore them too.

Hope you learned something :)

Thank you for reading :) :)

> #### This post was originally posted in the newsletter [GitBetter](https://gitbetter.substack.com/). If you are interested in leveling up your game in Git, you can subscribe to it.