How do I run git log to see changes only for a specific branch?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
git log becomes noisy quickly in repositories with active branching. Most of the time, the real question is not “show me every commit reachable from this branch,” but “show me what is unique to this branch compared with some base branch.” Git can answer that cleanly, but the range syntax matters.
Start with a Plain Branch Log
If you just want the history reachable from a branch tip, give git log the branch name:
This shows commits reachable from feature/auth-rework, including commits that also exist on main. It is useful for a general look, but it does not isolate branch-only work.
For a compact view:
For a graph view:
These views are helpful, but they still include shared history.
Show Commits Unique to One Branch
To see commits that exist on your branch but not on main, use two-dot range syntax:
Interpretation:
- left side is the baseline
- right side is the branch you care about
- output is everything reachable from the right side and not from the left side
This is usually the best answer to “what changed only on this branch.”
If you are currently checked out on the branch, HEAD is often more convenient:
That avoids hard-coding the current branch name.
Compare in the Other Direction
If you want to know what main has that your branch does not, reverse the range:
This is useful when you are preparing to rebase or checking whether your feature branch is behind.
Use Three Dots for Symmetric Difference
Three-dot syntax answers a different question: what commits are on either branch but not both.
With --left-right, Git prefixes commits so you can see which side they belong to. This is helpful when reviewing divergence between branches rather than just branch-only work in one direction.
Include File-Level Details
Commit messages are not always enough. Add file detail when you need to review what actually changed.
Names and status:
Diff summary:
Full patch:
Use patch output carefully on large branches because it gets long fast.
Filter by Author, Date, or Path
Range syntax combines well with other filters.
By author:
By date:
By path:
The -- separator matters when filtering by file or folder path.
Fetch Before Comparing
Branch comparison is only useful if your local refs are current. If you compare against stale local main, the output can be misleading.
This is a better habit than comparing against an outdated local branch pointer.
Useful Review Workflow
A clean pre-review sequence often looks like this:
- fetch the latest remote refs
- inspect unique commits on the current branch
- inspect file-level changes
- confirm there are no unintended commits
Example:
That gives a good pull-request sanity check before pushing or opening review.
Common Pitfalls
The most common mistake is running git log branch-name and assuming the result is unique to that branch. It is not. It is simply everything reachable from that branch tip.
Another issue is mixing up two-dot and three-dot syntax. Two dots answer a one-direction comparison. Three dots show the symmetric difference.
Developers also often compare against stale local main instead of freshly fetched origin/main, which produces incorrect conclusions about what is unique to the branch.
Summary
- Use
git log base..branchto see commits unique to one branch. - Use
git log branchonly when you want all history reachable from that branch tip. - Use three-dot syntax with
--left-rightfor symmetric branch comparison. - Add
--name-status,--stat, or-pwhen commit messages are not enough. - Fetch before comparing so branch-specific history reflects current remote state.
Related reading
- How do I safely merge a Git branch into master?
- How do I see the commit differences between branches in git?
- How do I set GIT_SSL_NO_VERIFY for specific repos only?
- How do I set up a Kafka service on gitlab-ci.yml?
- How do I show my global Git configuration?
- How do I show the changes which have been staged?
- How do I squash my last N commits together?
- How do I squash two non-consecutive commits?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.