IT:AD:Mercurial:HowTo:Branch and Merge
Summary
There are several ways to handle branching in Mercurial: cloning, and branch merging.
Process
Cloning
Cloning is the process of pulling down a second copy of the Repo, and working on it.
CloneA -> [a] -> [b] -> [c] //Download another repo CloneB -> [a] -> [b] //and work on it: CloneB -> [a] -> [b] -> [x] -> [y] //unaware of changes made in any other branch CloneA -> [a] -> [b] -> [c] -> [d]
When ready to checkin changes made to CloneB, you'll have to first pull down and Merge any changes from CloneA before you can push the changes you made.
- Pros:
- Great to take a copy and mess around to see if the idea can be done, and then chuck it in.
- Cons:
- Can checkin but not push until you're ready to add the code to CloneA
- No history beyond whatever you put in your notes.
- It's not really branching, as much as simply working off from RepoA on your own till done.
- More of an all or nothing solution.
Named Branches
The alternate is to use the same Repo with Named Branches.
By default checkins are done to the 'default' branch (note that when it's default, you don't even see it).
Checkin code to a named branch by following the following steps:
- Checkin, and on the Commit screen, change the
Branchfrom default to something else. - Once set, subsequent checkins will be checked in with that name.
- When someone else downloads the repo, from their point of view (ie Default), they'll see:
Switching back to Default
- IMPORTANT: First Checkin your codes to your side branch (
investigations/01)- If you don't check in these changes, they'll be lost when you switch over.
- Perform an update to switch branch:

