Compare (Diff) branches in Tortoise Git, or how to preview changes before doing a merge

I’ve recently switched over from SVN to Git in my version control. I’m a Windows user who’s used TortoiseSVN, so I was glad when I found out about TortoiseGit, which presents a very similar user interface to good ol’ TortoiseSVN. Still, there was lots to learn, as Git has a fundamentally different logic in storing the repository, both locally and remotely. Committing changes is a two step process unlike SVN’s single step.

Anyway, when doing software development in a project with several developers developing many braches, it’s sometimes nice to be able to take ‘sneak peek’ into the future and see what will happen when the branches are finally merged to one.

So how do you answer the question “what changes would be made if I merged these two branches right now?” Will there be any conflicts, for example? You could of course pull the changes from one branch to the other, but that is not always desirable.  There is a way to compare branches in TortoiseGit, but it’s faily well hidden by default.

Here’s how you can preview the changes before actually making them:

  • Shift-“right click” on your git folder
  • Select TortoiseGit >> Browse Reference

  • Select two branches from the list (hold shift to select more than one)
  • Right click and select “Compare selected refs”

This opens a window that displays the diff between the branches. Note that the diff is displayed as if the bottom branch (“Version 2”) was merged into the top branch (“Version 1”). There’s an arrow button at the top that lets you change the direction of comparison.

4 comments

    1. roger, no, its hidden in menu, use “settings” -> “set extend menu item” and UNcheck “Browse Reference” – this way it will appear in default context menu.

  1. Great Tip! coming from tortoise SVN it wasn’t clear how to do this.
    My default installation has “Browse Reference” unchecked in the menu settings, but one thing to note…. “Browse Reference” doesn’t appear if you have a file selected when you right click. Right click in the white space or on the folder.

Leave a Reply

Your email address will not be published. Required fields are marked *