Home > News > Mercurial Branching Cheat Sheet

Mercurial Branching Cheat Sheet

December 15, 2011

I have been using Subversion as source code version control tool since many years. Though I have used Mercurial for couple of hobby projects earlier but few weeks back, I started using it on my first Industrial project. Here, we are working on multiple feature-sets which need to go into Production at different time-lines. The best way to manage such scenarios is the use of branches. The concept and way of working with branches in Mercurial is quite different from Subversion. Here are few commands which one might find helpful while starting to work with Mercurial branches:

hg branches //shows all the branches present in the repository

There is always at-least one branch in Mercurial Repository which is called default as compared to trunk in Subversion.

hg branch new_branch_name //creates a new named branch

Named branches help in easy identification of the work being done on that branch.

hg commit //commits all the changes locally to the newly created branch
hg push --new-branch //pushes all the changes of this branch along with the branch to mercurial server

Only when we have committed and pushed our changes in newly created branch, other team members will be able to see the branch and our changes. Once a team member has committed the changes in a branch and other people would like to do further work on the same branch, they can use the following flow:

hg pull //gets all the changes on default as well as other branches
hg update -C branch_name //switches to the branch

On regular intervals, we will need to merge our changes from one branch to other for integrating different feature-sets. Following are the commands for the purpose

hg merge default //merges all the changes from default branch to your current working branch
hg commit //commits all the changes in your current working branch
hg push //pushes all the change-sets into the repository for other members to use them

For more detailed information on branching, please refer to branching tutorial available on Mercurial site.

About these ads
Categories: News Tags: ,
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: