Mercurial Introduction and Resources

Mercurial is a free, distributed source control management system for software developers. Mercurial is open-source, released under the GNU General Public License V2.

Mercurial is also a cross platform solution, as it is available for Windows, FreeBSD, Mac OS X and Linux operating systems.

Brief History

Mercurial was first released in April 2005 by its lead developer, Matt Mackall. Earlier that month, Bitmover announced the withdrawal of its free version of BitKeeper, which was used for version control in Linux kernel development. Mackall decided to develop Mercurial as a replacement for BitKeeper.

The Mercurial project was started a few days after a similar project with similar goals was created by Linux pioneer Linus Torvalds, called Git.

Eventually, the Linux kernel project adopted Git for version control, but Mercurial was adopted by many other development projects.

Mercurial is still actively developed, and the latest stable release is 3.8.4, dated July 1, 2016.

Mercurial features and design

Mercurial is designed as a distributed source control system. Distributed source control systems use a peer-to-peer approach, opposed to the client-server approach of centralized systems, which makes it possible for many developers to work on a project without requiring them to share a common network. Each peer’s working copy of the codebase is a complete repository, while a single, central repository does not exist. Network communication is only necessary when sharing changes among other peers, making it possible for developers to work when not connected to the network. Another advantage of distributed source control systems is that each working copy of the codebase effectively functions as a remote backup of the codebase and its change history, protecting against data loss.

Mercurial uses Secure Hash Algorithm 1 (SHA-1) hashes to identify revisions. For repository access over a network, Mercurial uses an HTTP-based protocol, but it can also communicate over SSH.

Mercurial’s implementation and data structures are designed and optimized for speed and high performance with high scalability. Most of Mercurial is written in Python, with a small part in portable C, therefore Mercurial binary releases are available for all major platforms.

The functionality of Mercurial can be modified with extensions, some of which are shipped with Mercurial, or you can download them from the project wiki.

Mercurial is a command-line driven program, with different graphical user interface (GUI) extensions available. Mercurial’s commands are issued as arguments to its driver program hg – a reference to Hg, the chemical symbol of the element mercury.

Using Mercurial

Mercurial is a popular choice for source control management, and although it was not selected to manage the Linux kernel development, it is used by many projects including Facebook, W3C and Mozilla.

Mercurial supports many workflow scenarios, both single user and multi user. The simplest workflow is Log keeping, where a single user wants to be able to log the changes they made, and check when those modifications were made.

The next workflow scenario is a single developer with nonlinear history, keeping track of changes and being able to revert to earlier versions and work onwards from there.

Mercurial also supports working on several features in parallel. To avoid mixing incomplete code versions, you can create clones of your local repository and work on each feature in its own code directory. When a feature is completed, you can pull it back into the main repository and merge the changes.

If you are not working alone and you want to share your changes to the code with others and include their changes, Mercurial allows you to do so very easily by using its built-in web server from which team members can pull changes.

In many cases, developers are not on the same network, so they cannot access Mercurial’s web server. In this case, changes can be exported and sent by e-mail, and team members can import them. Sending changes by e-mail is a nice way to reach team members who are not part of the regular development team, but it creates additional workload.

The best team workflow scenario is using a shared repository on a service like BitBucket. You need to setup a BitBucket account and create a new repository at BitBucket. Then you use Mercurial to push your local repository to the BitBucket repository, and your code is online. The rest of the developers also need to create BitBucket accounts, so you can add them to your BitBucket repository with the appropriate permissions. And that’s it, all team members can publish their changes to the online repository, and others can pull those changes to their local repositories.

Mercurial resources

Mercurial learning resources are scarce, since it is a very simple software solution, and the official website features a lot of high quality content. You will quickly learn Mercurial using the following resources:

Mercurial Books

Mercurial books are also quite rare, for the same reason. We suggest going through the online resources first, as they are really good, and learning Mercurial is very straightforward. We singled out these two books for people looking to master Mercurial:

  • Mercurial: The Definitive Guide (2009) by Bryan O'Sullivan: this free book gives a detailed and easy to read introduction to Mercurial and the philosophy behind it.
  • Instant Mercurial Distributed SCM Essentials How-to (2013) by Christophe Muller: this book will help you in exploring the basics as well as some of Mercurial’s most advanced features, such as extensions, hooks, conflict resolution, and so on through a comprehensive set of recipes. It quickly takes you through the process of creating a simple centralized software configuration workflow and continuous integration practice.


While Mercurial is a relatively mature source control management system, and it’s being actively developed, it’s not as popular as some alternatives.

Since its introduction, Git has overtaken Mercurial in terms of market share. Both systems are quite similar, although there are a number of technical distinctions which may apply to certain niches or projects. In recent years, Git started becoming a de-facto industry standard, while Mercurial has not.

Still, Mercurial compares favorably to older versioning systems such as Subversion, which is still widely used in some circles. Mercurial offers a compelling upgrade path for Subversion users, especially when integrated with a repository such as BitBucket. A lot of Mercurial hosting services have been launched in recent years, and users should have an easy time finding a host capable of handling their Mercurial needs.

Further Reading and Resources

We have more guides, tutorials, and infographics related to coding and development:

  • Version Control and Hosting: not just about hosting, but also a comparison of version control systems.
  • Ubuntu Primer: learn all about one of the most popular Linux distributions — an excellent base for MantisBT hosting.
  • Object-Oriented Programming: learn about the wide range of object-oriented programming languages — some may surprise you.

Would the Internet Survive the End of the World?

Have you ever wondered what a major catastrophe would do to the internet? Check out our infographic, Would the Internet Survive the End of the World? It's possible we could all be destroyed but the internet would live on.