May 09, 2026 · ~3 min read

10 Git Diff Commands Every Developer Should Memorise

When working with Git, understanding how to efficiently compare changes between commits, branches, and the working directory can save you a lot of time and headaches. Here are ten essential git diff commands that every developer should have in their toolkit.

1. Comparing Branches: git diff main...branch

The three-dot syntax is a powerful way to see what changes exist in a branch compared to another.


git diff main...feature-branch

This command displays the differences between the latest commit in feature-branch and the common ancestor commit shared with main. It helps you understand what new changes are introduced in the feature branch.

2. Viewing Staged Changes: git diff --cached

When you want to see what changes you've staged for the next commit, use the --cached option.


git diff --cached

This command shows differences between the staged files and the last commit. It's handy for double-checking what you're about to commit.

3. Summary of Changes: git diff --stat

Sometimes you just want a quick overview without diving into the specifics. The --stat option provides a summary of changes.


git diff --stat main...feature-branch

This command will give you a concise report of how many files were changed, added, or deleted along with the number of lines added and removed.

4. Only File Names: git diff --name-only

If you only need to see which files have changed, --name-only can help you avoid the noise of actual code differences.


git diff --name-only main...feature-branch

This command lists the names of files that have been modified, added, or deleted in the specified diff range.

5. Short Summary of Changes: git diff --shortstat

For a quick summary of file changes and line counts, use the --shortstat option.


git diff --shortstat main...feature-branch

You'll get a brief output summarizing the changes, including the number of files altered, insertions, and deletions.

6. Ignoring Whitespace: git diff -w

Whitespace changes can clutter your diff output. Use the -w option to ignore these.


git diff -w main...feature-branch

This command only shows changes that are not affected by whitespace, making it easier to focus on critical code changes.

7. Control Context Lines: git diff -U0

Sometimes, you might only want to see the lines that have changed without any surrounding context. The -U0 option is perfect for that.


git diff -U0 main...feature-branch

This command limits the diff output to the exact lines that were changed, making it concise and to the point.

8. Highlighting Changes: git diff --color-words

For a more granular view of changes, --color-words highlights word changes instead of line changes.


git diff --color-words main...feature-branch

This is especially useful for reviewing small changes in text files, as it visually distinguishes what has been added or removed.

9. Checking for Issues: git diff --check

Before committing, you might want to check for potential issues such as whitespace errors. The --check option can help you catch these.


git diff --check

This command will warn you about whitespace errors and other potential issues in your unstaged changes.

10. Understanding Three-Dot vs Two-Dot Diff

The difference between the three-dot (...) and two-dot (..) syntax is crucial for effective diffing.

```bash

git diff main..feature-branch

```

This displays changes in feature-branch since it diverged from main.

```bash

git diff main...feature-branch

```

This option provides a broader perspective by comparing the latest commit in feature-branch against the last shared commit with main.

Wrapping Up

Mastering these git diff commands will streamline your workflow and enhance your code review process. With tools like PullRequestAI, generating descriptive pull request summaries from your diffs becomes effortless, allowing you to focus on writing great code. Don't underestimate the power of good diffs in your development process!

Stop writing PR descriptions. Paste your diff. Done.

PullRequestAI turns any git diff into a clean Markdown PR description in seconds. Free forever, no signup.

Try it now →