TortoiseHg integrates Mercurial with Windows Explorer

Developers on Microsoft Windows need distributed version control systems, too. That's where TortoiseHg comes in. Chad Perrin explains how to get started with TortoiseHg.

The Mercurial distributed version control system (DVCS) has the tools needed to support a very compelling workflow, offering freedom from a lot of the concerns over conflicting edits, long periods without commits when working on a hairy problem, and other issues that can arise with centralized VCSs (CVCSs). There is still a place in the world for CVCSs, but when a DVCS is the tool for the job, nothing else measures up.

Even though Mercurial is open source software with an excellent command line interface in the Unix tradition, that does not mean we cannot use it on Microsoft Windows systems. In fact, the default installer download for Microsoft Windows at the Mercurial site provides TortoiseHg by default. TortoiseHg integrates Mercurial with Windows Explorer and provides a robust GUI management interface.

Once TortoiseHg is installed, it's pretty easy to get started. Open the File menu and select either Clone Repository... or New Repository..., depending on whether you wish to create a local repository for a new project or create a local clone of a repository that already exists; the process for either is fairly obvious. The one likely point of confusion is the specific meanings of the Source: and Destination: fields when cloning; the source is the already existing repository you wish to clone, while the destination is where you want to place the clone on the local system.

The main interface for TortoiseHg is called the "Workbench." Most of your work will probably be done using the commit display of the Workbench window. Clicking the checkmark button at the top of the window will show that display mode.

Parts of the UI are not as well labeled as one might like. By default, the commit display offers:

  • a vertically aligned repository registry pane at the left-hand side that shows what local Mercurial repositories are being tracked
  • a horizontally aligned version history graph at the top
  • a vertically aligned pane that shows file status akin to the results of the hg status command below the history graph
  • a horizontally aligned and commit pane, also below the history graph and to the right of the status pane
  • a content pane in the bottom-right corner that shows the content changes of files selected in the status pane

The status pane shows a Stat column, with single character indicators that mark each listed file, such as a question mark for files that are not tracked by Mercurial, a capital M for modified files, and so on. Checkboxes are used to select (or deselect) files in the status pane whose changes may be included in the next commit. To commit, once you have ensured that any changed files you wish to commit (and only those) are selected in the status pane, simply type a brief message identifying the reason the commit was made into the commit pane and click the Commit button above it.

A series of four buttons at the top of the Workbench window showing small yellow cylinders, green arrows, and in two cases dotted outlines of cylinders, are used to pull changes from the remote repository with which the local repository is associated (if there is one), push committed changes to it, or check for changes that need to be pulled or pushed.

In addition to the Workbench interface, TortoiseHg adds status icons for files within any directory tracked by Mercurial when viewing them in Windows Explorer, and right-click context menus offer easy access to Mercurial functionality as well. With Windows Explorer integration and the Workbench, the functionality of Mercurial is made available.

As a whole, Mercurial itself (and thus TortoiseHg) is a rich, sophisticated toolset that offers far more capability than can be described in one article. The above only covers some of the basics to get you started. For those who prefer the hg command line interface, though, that too is available as part of the default download from the Mercurial site. Simply open a cmd window and use hg commands much as you would on a BSD Unix or Linux-based system.