Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Mercurial: Merging Branches

📅 2010-Aug-06 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ branching, mercurial, merging, tortoisehg ⬩ 📚 Archive


Mercurial users keep insisting that you do not really need to create actual branches to work. But, if you are one of the few who likes to do this, merging branches is just as easy too. I use TortoiseHg, but the equivalent command-line options are just as obvious.

  1. Consider branches A and B. You wish to merge B to A, so that work on A can continue. Typically, A might be the default branch and B can be a feature branch.

  2. Finish, test and commit all the files on both branches A and B.

  3. Open Repository Explorer. Update the working directory to branch A. This can be done by choosing the head of branch A, right-click and choose Update.

  4. Choose the head of branch B, right-click and choose Merge with. Tip of branch A will automatically be chosen as the target for the merge. Click Merge.

  5. Mercurial will try to merge the files automatically as much as possible. For the files with merge conflicts, it will pop up KDiff3 windows so you can pick the changes you want merged. The conflict windows are displayed sequentially, finish one and the next one is displayed.

  6. Settle all the conflicts and your merge is done! Branch B should be connected to branch A nicely in the graph displayed in Repository Explorer now.

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘📧