How do you handle the default branch in Mercurial?

We've got a repository with two named branches in it: dev and production. There's also the default branch, which we aren't using. Unfortunately, whenever people clone the repository, it automatically puts them on default, and we're having problems because people will inadvertently commit to it.

Is there a way to delete the default branch, or disable it, or set Mercurial so that clones will automatically start on the dev branch?


The mercurial documentation has some examples of precommit hooks and one, ironically, is checking the branch name. In the example, it checks to make sure it matches a regular expression. You could tweak it to make sure the name isn't "default".

This may not prevent the clones from starting on the "default" branch, but at least with this hook in place, no one can put any code into "default".


This answer has become outdated: you can now add a @ bookmark and Mercurial 2.4 and later will automatically check it out for a new clone. Your users will have to be careful about keeping the @ bookmark pointed at the branch head they want, though.


You cannot make another branch the default branch, by which I mean you cannot tell Mercurial that you would like branch-X to be checked out in a new clone. You should always make default the branch the branch that users want to checkout. This is described in the wiki.

People sometimes try to delete the default branch. This can be done by not creating one in the first place:

$ hg init repo
$ cd repo
$ hg branch dev
$ hg commit -m "Ha, no default branch!"

When there is no default branch present, hg clone will checkout the tip-most changeset. This is a bad idea since this changeset changes every time something is pushed to the repository. So if you have a dev and prod branch in the repo, then a new clone will checkout a "random" changeset depending on where the last commit was made. That is even more confusing that teaching people that default means "the normal branch where you should work by default".