SourceTree and Gerrit

Gerrit & SourceTree

SourceTree is a free GUI for git and mercurial produced by the people at Atlassian and I love it. It’s brilliant at loads of things, but I particularly find it useful for repo visualisation.

One of the cool features of SourceTree is that you can add arbitrary commit text replacements. For example, if you use Jira as a project tracking tool, SourceTree can find references to issues and turn them into links:

Jira Commit Message

Setting this up is really simple:

  1. In SourceTree, when viewing your repo click the Settings button on the right hand side of the tool bar.
  2. Then click Advanced.
  3. You can then Add a Commit Text Replacement. Set the two required fields:

Jira Link

It really is that easy.

It’s also possible to add custom regex-based text replacements. For example, if you use gerrit (a brilliant open source git-based code review tool) then commit messages can have change-ids added. These allow for multiple changesets be linked together for the same commit - an essential part of the code review process.

Gerrit is a web-based tool, with each changset having its own URL. Using the SourceTree regex text replacement, we can change the change-ids present in the commit messages into links:

Gerrit Commit Message

To set this up, we add a new Commit Text Replacement (as with the aforementioned Jira link), but select the type to be other.

We use the following regex pattern, which picks out the 40 character hex-hash, prefixed with a capital I:


And then the replacement is a correctly constructed HTML link:

<a href="$1,n,z">$1</a>

This uses the gerrit query URL to search for the requested gerrit ID.

I find this tip really useful to see who reviewed commits which have been through gerrit, and to add reviewers to commits I have just pushed. Hope it helps somebody else as well.