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
Was it useful? Share this post with the world!

8 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 “..” πŸ˜›

    1. Worked for me too, just now. Got new branch from collaborator with no apparent changes (?), ran command with both space and .. delimiters. Both worked and confirmed that branch creator had made zero changes in that branch.

  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

  5. To show only files that are different between the two branches (without changes themselves):
    git diff develop..master –name-status

  6. Should be
    git diff develop..master –name-status
    in the above comment

  7. When I press ‘Post’, the editor is converting my minus minus before name-status into a long hyphen!

Leave a Reply