Creating a new branch in Mercurial

A really good guide on branching is available here:

In my case, I wanted to branch a previous version of my code to launch a parallel branch for bug-fixing of the previous release. I used the Chamilo code repository on google code. I already had a local copy (in /var/www/chamilo), so what I did was:

  • cd /var/www
  • hg clone chamilo -r [the changeset of the previous release, in my case 5c49a5e35ade ] chamilo- (this last bit is the destination dir)
  • cd chamilo-
  • hg branch (from there on, the default destination for my commits here will be the “”, which will only exist after my first commit)
  • did some changes
  • hg commit -m “Fixed security flaw …” index.php
  • hg branches (this shows that there are effectively 2 branches, the “default” and the “”)
  • hg log -l3 (shows that we are effectively at changeset 5c49a5e35ade + 1 commit)
  • hg push –rev (with double dash) (this pushes only in branch – this triggers a warning asking me to confirm the creation of a new branch in the upstream repository)
  • hg push –new-branch –rev (these are  two double ‘-‘, by the way)
  • because I cloned from the local repository, I actually just pushed in my “local upstream”
  • cd ../chamilo
  • hg push –new-branch –rev

Done. Now all normal people will keep sending to the default Chamilo branch, but anyone wanting to improve will just be able to commit to that branch. Not sure yet that “” was the right name choice, but it’s too late to lament on that.

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *