Git – Diff Between Branches

When you are working with multiple branches in Git, it’s important to be able to compare them and contrast the differences.

In this short note i will show how to compare two branches in Git using the git diff command.

I will show how to git diff between any two branches, e.g. current branch and master or git diff between master and staging and how to list only files that are different between two branches (without changes themselves).

Cool Tip: How to git diff staged and unstaged files! Read more →

Git – Diff Between Branches

Diff between current branch and master:

$ git diff master

Diff between two branches, e.g. master and staging:

$ git diff master..staging

Show only files that are different between the two branches (without changes themselves):

$ git diff --name-status master..staging

4 Replies to “Git – Diff Between Branches”

  1. Just a quick note – the diff will not work if you put a “..” between the names of the branches; should just be a space.

  2. Somehow it worked for me with the “..” 😛

  3. Nothing happens when I run it any of the following ways:
    git diff myNonCurrentBranch
    git diff myBranch1 myBranch2
    git diff myBranch1..myBranch2
    git diff origin/myBranch1 origin/myBranch2
    git diff origin/myBranch1..origin/myBranch2

  4. If it doesn’t work, try to use the complete name of the branch, the same you see when launching git branch -a

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.