Review Git PRs with Beyond Compare

Whether you are using GitHub Desktop or Atlassian’s SourceTree (or their respective web views), it is always nice to use an external diff editor.

My diff editor of choice Beyond Compare. Don’t ask me why. Probably because I started on Windows, and it came bundled with Delphi. Nowadays, I’m mostly on Mac and Beyond Compare is cross-platform. Anyway, all diff editors out there are pretty good.

Let’s get started. At a terminal prompt, enter these commands:

git config --global diff.tool bc
git config --global difftool.bc.trustExitCode true

On Windows, you will need to enter this additional command:

git config --global difftool.bc.path "c:/Program Files/Beyond Compare 4/bcomp.exe"

When you’re ready to commit your changes to your repo, use this command to compare them:

git difftool

That’s nice and all, but if you’re reviewing someone else’s code, then you’re not really interested in differences between two commits, because your colleague’s branch might contain many of them. You will want to compare all of the work done since it diverged from master.

bcreview is a useful command to do code reviews (shamelessly “borrowed” from ksreview by Doug Russell and Kevin Ballard).

To install bcreview simply enter this command:

git config --global alias.bcreview '!f() { local SHA=${1:-HEAD}; local BRANCH=${2:-master}; if [ $SHA == $BRANCH ]; then SHA=HEAD; fi; git difftool -y -t bc $BRANCH...$SHA; }; f'

To use bcreview while you’re on a branch, assuming your mainline branch is master, just enter this command:

git bcreview

If you’re on a different branch or your mainline isn’t master, you can be more specific:

git bcreview feature-branch-name mainline-branch-name

To the friendly people at Scooter Software: please allow me to comment on code from within Beyond Compare (without switching to the pull request on the web), because that would then make your product shine and leave the competition in the dust.