Compare branches
Intermediate Git CLI VS Code UI IntelliJ UI GitLab UI GitHub UI
Why this matters
Before you ask for review, you should know exactly what you are asking someone to read. Comparing your branch with main answers that in two commands, and it catches the two classic surprises: a file you did not mean to change, and a commit from another branch that came along by accident.
The two-dot range: what the branch adds
$ git log --oneline main..docs/12-windows-install-steps510f1e0 docs: add Windows steps to installation guide (#12)Read main..docs/12-… as "commits reachable from the branch but not from main". One commit, so this branch adds exactly one thing. Reverse the order to ask the opposite question, "what has main gained that my branch lacks", which is the same as "how far behind am I":
$ git log --oneline docs/12-windows-install-steps..mainEmpty output means the branch is up to date with main.
Summarizing the files
$ git diff main..docs/12-windows-install-steps --stat docs/getting-started.md | 4 ++++
1 file changed, 4 insertions(+)One file, four added lines. That is the review you are about to request. Drop --stat for the full diff, or add a path to focus: git diff main..docs/12-… -- docs/.
Two dots and three dots
git diff accepts both, and they answer different questions:
| Form | Compares | Answers |
|---|---|---|
git diff main..branch |
the tip of main with the tip of the branch |
"How do the two versions differ right now?" |
git diff main...branch |
the branch with the point where it left main |
"What did this branch change?" |
While your branch is up to date with main, both give the same answer:
$ git diff main...docs/12-windows-install-steps --stat docs/getting-started.md | 4 ++++
1 file changed, 4 insertions(+)They diverge once main moves ahead. Then two dots also shows main's new work as if you had removed it, which is confusing and almost never what you want. Three dots is what a merge request shows, and it is the safer habit for reviewing your own branch.
How to do it
$ git log --oneline main..docs/12-windows-install-steps
$ git diff main...docs/12-windows-install-steps --statThe first says which commits, the second which files. Run both before opening a merge request.
- Open the Source Control Graph in the Source Control view: your branch's commits sit above the point where it left
main, so the range is visible at a glance. - For a file-level comparison, install GitLens and use Compare References… from the Command Palette, choosing
mainand your branch; the result is a diff list you can click through. - Without GitLens, open the integrated terminal (Ctrl+`) and use the two commands from the Terminal tab.
- Open the Git tool window → Log tab (Alt+9 / ⌘9).
- In the branches popup (status bar, bottom right), point at
main→ Compare with current. A dialog lists the commits each side has and the changed files. - Or right-click your branch in the Log → Compare with 'main'.
Code → Compare revisions: pick main as the source and your branch as the target (or the other way round; the page explains which is which) and press Compare. You get the commit list and the diff.
An open merge request shows the same thing permanently: the Commits tab is git log main..branch and the Changes tab is git diff main...branch. That is why the numbers on a merge request sometimes differ from a plain two-dot diff.
https://github.com/<org>/<repo>/compare/main...my-branch compares any two points; the three dots in that URL are the same three dots as in git diff, which is not a coincidence. The branch dropdown on the Compare page builds the URL for you.
A pull request's Commits and Files changed tabs are the same two views.
Common mistakes
- Comparing with a stale
main. Your localmainmay be days old.git fetchfirst, or compare againstorigin/maindirectly:git log --oneline origin/main..HEAD. - Using two dots in
git diffaftermainmoved. The output includesmain's new work inverted. Use three dots. - Forgetting
--before a path that looks like a branch name. - Reading the file count as the review size. A one-line change to a lock file is not the same work as a one-line change to a paragraph; look at the diff, not only the count.
Try it yourself
Goal: describe your own branch the way a reviewer will see it.
- From an up-to-date
main, createdocs/practice-compare, make two commits touching two different files. - Run
git log --oneline main..docs/practice-compare. - Run
git diff main...docs/practice-compare --stat. - Move
mainforward with one commit, then run both the two-dot and the three-dot diff and compare the output.
Expected result: step 2 lists your two commits; step 3 lists your two files; in step 4 the two-dot diff also mentions the file you changed on main, while the three-dot diff still shows only your two.
Show solution
The three-dot form compares your branch against the commit where it left main, so main's later work never appears. That is what a merge request shows, and why it is the honest answer to "what does my branch change?". Clean up with git switch main and git branch -D docs/practice-compare.