All commands

git blame

intermediate

Attribute every line of a file to the commit and author that made it.

What it does

git blame walks the commit graph for one file and, line by line, reports which commit (and thus which author and when) last touched that line. It's the forensic tool for 'who wrote this and why.'

@@ -1,3 +1,3 @@ src/App.tsxMyers diff → edit script
const header = 'OLD'
const header = 'NEW'
const nav = [ 'home', 'about' ]
const nav = [ 'home', 'about', 'blog' ]
return <div>
return <div>

Each line carries its origin commit — the effect of blame

Watch it — press play

A narrated, step-by-step walkthrough that shows how to do it — not just theory. It adapts to the learner mode you picked in the top bar.

1 / 2

Step 1

Find the culprit (politely)

git blame walks the file's history backwards and marks every line with the commit that introduced it.

git blame src/main.ts
@@ -1,3 +1,3 @@ src/App.tsxMyers diff → edit script
const header = 'OLD'
const header = 'NEW'
const nav = [ 'home', 'about' ]
const nav = [ 'home', 'about', 'blog' ]
return <div>
return <div>

Every line now wears its origin commit

Under the hood

1

Backward diff walking

Blame starts at the current version of the file and walks backwards commit by commit, diffing consecutive versions. When an old line disappears from the diff, Git credits the commit that introduced it.

previous blob ──diff──> next blob
lines removed leave a mark → attributed to that commit
2

Renames and splices are tracked

With follow mode (git blame -M -C), Git detects lines copied within a file or across files and re-attributes them to the origin commit — even through renames.

Aliases the pros type

Memorize the git blame concept, then let one of these shortcuts make it instant. Aliases are real git config keys — add one with:

git config --global alias.st # → git blame -L
AliasWhy people use it
g bl

Blame a specific line range you care about.

g blame

Noise-reduced blame with move detection.

Command anatomy

git blame <file>
-L <start>,<end>

Only blame a line range (fast for large files).

-M

Detect lines moved within the same file.

-C

Detect lines copied from other files.

-w

Ignore whitespace changes when matching.

When to reach for it

'Why is this line like this?' → blame it, read the message, see the PR.

Finding who last edited a risky function before you touch it.

Code archaeology over 10k-line files, focusing -L on the hot spot.

Pro tip

These days blame is a stepping stone: the second you identify a suspicious commit, jump to its message with `git show <hash>` — the message usually documents exactly why the line exists.

Go deeper with