Creating a new branch in Mercurial

A really good guide on branching is available here: http://stevelosh.com/blog/2009/08/a-guide-to-branching-in-mercurial/ 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-1.8.8.6 (this last bit is the destination dir)
  • cd chamilo-1.8.8.6
  • hg branch 1.8.8.6 (from there on, the default destination for my commits here will be the "1.8.8.6", 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 "1.8.8.6")
  • hg log -l3 (shows that we are effectively at changeset 5c49a5e35ade + 1 commit)
  • hg push --rev 1.8.8.6 (with double dash) (this pushes only in branch 1.8.8.6 - this triggers a warning asking me to confirm the creation of a new branch in the upstream repository)
  • hg push --new-branch --rev 1.8.8.6 (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 1.8.8.6
Done. Now all normal people will keep sending to the default Chamilo branch, but anyone wanting to improve 1.8.8.6 will just be able to commit to that branch. Not sure yet that "1.8.8.6" was the right name choice, but it's too late to lament on that.

Comments