git diff <branchname1>..<branchname2>

Show all code changes between two branches as a unified diff.

This command is useful to review what has changed between two branches before merging or creating a pull request, by showing a line-by-line diff of the final snapshots of both branches.

This command uses git diff to compare the tips of two branches, where <branchname1> and <branchname2> are branch names (for example, main and feature/login-form), and the ..<..> syntax tells Git to diff the full contents of those two branch heads against each other. The first branch <branchname1> is treated as the “old” side and the second branch <branchname2> as the “new” side, so added lines appear with + and removed lines with - relative to <branchname1>. You can add flags like --stat to see only a summary of changed files and line counts, --name-only to list just the filenames that differ, or --color (often enabled by default) to highlight additions and deletions.

You can combine this with other options such as --word-diff for inline word-level changes, --cached (if you were diffing against the index instead of another branch), or -- <path> to limit the comparison to a specific file or directory, for example git diff main..feature/login-form -- src/components/. A closely related variation is git diff <branchname1>...<branchname2>, which uses the merge-base between the branches to show changes on <branchname2> since they diverged from <branchname1>, and is often more useful for code review. Other commands that complement this include git log <branchname1>..<branchname2> to see commit history differences, and git diff --staged to review staged changes before committing.

Examples:

  • git diff main..feature/login-form
  • git diff develop..release --stat
  • git diff main..feature/payment -- src/payments/
Manual page
git diff
Related commands

Welcome to GitExamples!

Sign in to gitexamples