Skip to main content
v2026.11,986 entries · CC-BY 4.0

Compare Two Branches in Git: git diff, Two-Dot vs Three-Dot, and GitHub Compare

Compare two branches in Git with git diff, choose between two-dot and three-dot, and use the GitHub compare view, with each step taken from official docs.

Written and maintained by CASRAI Editorial Board

Published · Last updated

On this page

To compare two branches in Git, run git diff branch-a..branch-b for the difference between the two branch tips, or git diff branch-a...branch-b for only what branch-b added since the two branches diverged. On GitHub, open the repository’s compare view and choose a base and a compare branch. The two-dot and three-dot forms answer different questions, and the choice decides which changes the comparison shows.

The rule to keep: use three dots when you ask “what did my branch change?”, and two dots when you ask “how do these two tips differ right now?”. GitHub pull requests use the three-dot form, so a local three-dot diff is the one that matches what a reviewer will see.

What it is used for in research

Research groups keep analysis scripts, manuscript sources and processing pipelines in Git repositories, often with one branch per analysis or revision round. Comparing branches before a merge shows exactly which scripts, parameters and data-handling steps changed, which supports a record of what was altered between a submitted analysis and a revised one. It also pairs naturally with a documented workflow for research software and reproducibility; see the GitHub tutorials for beginners guide for the wider platform context.

Install or access (official source only)

Local comparison uses git diff, a command built into Git and documented in the official reference at git-scm.com/docs/git-diff. The GitHub route needs only a browser: according to GitHub Docs, you can append /compare to your repository’s path, which gives https://github.com/OWNER/REPOSITORY/compare. If you prefer to drive GitHub from a terminal, see how to install GitHub CLI.

Step-by-step: compare two branches

Compare two branches with git diff (git compare branches)

  1. Open a terminal in your repository.
  2. Run git diff main..feature (replace the names with your branches). The Git manual states that the two-dot form is synonymous with the form without the dots, so git diff main feature gives the same result. It shows the changes between two arbitrary commits, here the tips of the two branches.
  3. If you leave one side out, the Git manual says it has the same effect as using HEAD. With feature checked out, git diff main.. compares main with your current commit.
  4. Both branch names are given as arguments, so the command compares the two commits directly. If you have unfinished local edits you want to set aside before reviewing, see stashing changes in Git.

Show only what a branch added (three-dot form)

  1. Run git diff main...feature.
  2. Per the Git manual, this shows the changes on the branch containing and up to the second commit, starting at a common ancestor of both. It is equivalent to git diff $(git merge-base main feature) feature.
  3. Use this when you want the contribution of feature alone, ignoring commits that landed on main after the branches diverged.

Limit the comparison to files or a summary

  1. Add a path after -- to restrict the diff: git diff main...feature -- analysis/. The synopsis in the Git manual is git diff [<options>] <commit>...<commit> [--] [<path>...].
  2. For a quick overview, add one of the output options described below.

Compare two branches on GitHub (github compare two branches)

  1. Go to https://github.com/OWNER/REPOSITORY/compare, or append /compare to your repository’s path.
  2. In the base dropdown, choose the branch you want to compare against.
  3. In the compare dropdown, choose the branch that contains the changes.
  4. Review the commits and changed files shown on the page.

Output and how to read it

By default git diff prints the full patch. These options from the Git manual condense it:

Option What the manual says it does Use it when
--stat Generates a diffstat You want per-file counts of changes
--shortstat Outputs only the last line of the --stat format: total modified files and added and deleted lines You want one summary line for the whole branch
--name-only Shows only the name of each changed file in the post-image tree You need a list of files to review or script against
--name-status Shows only the name and status of each changed file You need to see which files were added, modified or deleted

Two dots versus three dots: which diff is GitHub showing? (difference between .. and …)

GitHub Docs state that pull requests on GitHub show a three-dot diff: the comparison of the merge base against the latest version of the topic branch. A two-dot diff compares the latest state of the base branch with the latest state of the topic branch, so, in GitHub’s words, the diff changes when the base branch is updated, even if the topic branch has not been touched. GitHub advises merging the base branch into your topic branch frequently to avoid confusion, and says that after you merge the base branch, the two-dot and three-dot diffs are the same.

Question Command Compares
What did my branch add? git diff main...feature Common ancestor (merge base) against feature
How do the two tips differ now? git diff main..feature Tip of main against tip of feature

Troubleshooting

  • The diff changed but my branch did not. You are probably looking at a two-dot diff and the base branch moved. Use the three-dot form, or merge the base branch into your branch.
  • My local diff does not match the pull request. Pull requests use three dots, so run git diff base...topic locally.
  • The output is too long to read. Add --stat, --shortstat or --name-status, or limit the diff to a path after --.

Other ways to compare branches

Method Where it runs Documented by
git diff two-dot or three-dot Local terminal Git reference manual (git-scm.com)
Compare view with base and compare dropdowns GitHub, in the browser GitHub Docs, “Comparing commits”
Pull request diff (three-dot) GitHub, in the browser GitHub Docs, “About comparing branches in pull requests”

If you landed here because you want to undo local edits rather than compare them, see discarding local changes in Git.

FAQ

How do I compare two branches in Git?

Run git diff branch-a..branch-b to compare the two tips, or git diff branch-a...branch-b to see what branch-b added since the common ancestor.

How do I compare two branches on GitHub?

Open https://github.com/OWNER/REPOSITORY/compare, choose the base branch to compare against and the compare branch that contains the changes, then review the commits and files.

What is the difference between .. and … in git diff?

Two dots compare the two branch tips directly. Three dots compare the second branch against the merge base of the two, which is the view GitHub pull requests show.

Can I compare branches without checking them out?

Yes. git diff takes the two branch names as arguments and compares the commits they point to, so neither needs to be checked out.

Sources (official docs, date checked 2026-10-29)

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Compare Two Branches in Git: git diff, Two-Dot vs Three-Dot, and GitHub Compare

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →