Search code examples
mercurial

Create a new branch at a certain revision


With mercurial it is easy to create a tag at a certain revision: hg tag -r <revision> <tag-name>. But how to create a branch at a certain revision?


Solution

  • Preface: Mercurial branches are two types:

    • named branch
    • anonymous

    Named Branch

    In order to get named branch BRANCHNAME, starting at REV

    hg update REV
    hg branch BRANCHNAME
    ...
    hg commit
    

    commit is a must, because

    the branch will not exist in the repository until the next commit

    as noted in hg help branch

    Anonymous branch

    hg update REV
    ...
    hg commit
    

    and current branch get additional head


    And as a last step, use the following command to create a remote branch and push the changesets.

    hg push --new-branch