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-18.104.22.168 (this last bit is the destination dir)
- cd chamilo-22.214.171.124
- hg branch 126.96.36.199 (from there on, the default destination for my commits here will be the "188.8.131.52", 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 "184.108.40.206")
- hg log -l3 (shows that we are effectively at changeset 5c49a5e35ade + 1 commit)
- hg push --rev 220.127.116.11 (with double dash) (this pushes only in branch 18.104.22.168 - this triggers a warning asking me to confirm the creation of a new branch in the upstream repository)
- hg push --new-branch --rev 22.214.171.124 (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 126.96.36.199
I needed to enter hg --new-branch, not hg -new-branch, note the double hyphen.