Naming Branches Within One Repository

In most instances, isolating branches in repositories is the right approach. Its simplicity makes it easy to understand, so it’s hard to make mistakes. There’s a one-to-one relationship between branches you’re working in and directories on your system. This lets you use normal (non-Mercurial-aware) tools to work on files within a branch/repository.

If you’re more in the power user category (and your collaborators are too), there is an alternative way of handling branches that you can consider. I’ve already mentioned the human-level distinction between little picture and big picture branches. While Mercurial works with multiple small-picture branches in a repository all the time (for example after you pull changes in, but before you merge them), it can also work with multiple big-picture branches.

The key to working this way is that Mercurial lets you assign a persistent name to a branch. There always exists a branch named default. Even before you start naming branches yourself, you can find traces of the default branch if you look for them.

As an example, when you run the hg commit command, and it pops up your editor so that you can enter a commit message, look for a line that contains the text HG: branch default at the bottom. This is telling you that your commit will occur on the branch named default.

To start working with named branches, use the hg branches command. This command lists the named branches already present in your repository, ...

Get Mercurial: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.