Home > Development, Documentation, English, Organisation > Creating a new branch in Mercurial

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- (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.

  1. Neil
    May 20, 2013 at 1:11 pm

    I needed to enter hg –new-branch, not hg -new-branch, note the double hyphen.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: