When you want to compare two branches, use git diff
. I usually like to pair it with the --stat
option for a quick visual summary.
# Compares branch1 to branch2
git diff branch1..branch2 --stat
# By ommitting the second branch name, git assumes I mean
# "the current branch"
git diff main.. --stat
Git diff branch_name..
Let’s say I’m on a test branch, and I want to see how that branch differs from main
. I can get a quick overview via git diff main.. --stat
:
The regular git syntax here is git diff branch1..branch2
, but by omitting branch2
git assumes I mean use the current branch
.
For clarity, here’s the same comparison but with the branches in reverse order:
I almost always use the --stat
option for a quick filename summary. There could be a big difference between branches, and I don’t want to accidentally print hundreds of lines to stdout.
Note: git diff only reads changes that have already been committed. If you have un-committed changes git diff
won’t show them.