How to branch with TortoiseHG

87,130

Solution 1

As shown in the docs, all you should need to do is just click on the branch: default button near the top of the commit dialog, and change to a new branch name.

Solution 2

To start new branch with TortoiseHg press Commit... then, above Commit message press Branch, then "Open new named branch: "

Solution 3

Just wanted to add that in order to push new branch to remote repository there is a checkbox on the Synchronize tab under Options of "Allow push of a new branch" - you have to remember to turn it off again right afterwards.

Solution 4

Most of the time in mercurial, you clone the repository to make a branch.

You can then merge the separate repositories once you made your edits and commits.

This might sound like it would take up a lot of disk space but on most operating systems, mercurial will make hardlinks instead of copying the files. Anyway, disk space is normally cheap, and because it's local it's rather fast.

If you think about it, every "checkout" (in svn terminology) or "clone" (in mercurial terminology) is really a branch that will probably be merged back so it makes lots of sense that clones are the common way of making branches.

Share:
87,130

Related videos on Youtube

Michael Tiller
Author by

Michael Tiller

I have a Ph.D. in Mechanical Engineering but lots of practical experience in the programming and IT side. I'm also the Founder and President of Xogeny. I blog about mostly mathematical modeling but also about software and IT topics at the Xogeny Company Blog.

Updated on April 26, 2020

Comments

  • Michael Tiller
    Michael Tiller about 4 years

    I downloaded TortoiseHg 1.0 for evaluation. For the life of me I can't figure out how to make a branch. It seems to understand branches (e.g. in its repository browser) but I just can't seem to find a way to make a branch. This seems like such a fundamental capability since out of the often touted benefits of DVC is the lightweight branching.

    I Googled around and couldn't find much discussion of this topic (at least for recent versions) so I have to assume I'm missing something, right?

    Update: So I flagged Chad Birch's answer below to answer the "new branch" issue. As he correctly points out, you do a commit and then click on the branch button to bring up the branch maintenance dialog which is where you create new branches. I kind of wish they had given us a context menu option for this. Once you've branched, the next natural question is how to merge and this is also not obvious. It turns out that option is buried in the repository explorer. You need to select the head of another branch, right-click and then select "Merge with...".

    • arclight
      arclight about 8 years
      Branching is seriously buried in a completely unintuitive aspect of workflow. Branching and committing are two very distinct operations and it makes no sense to bury branching deep within the commit UI. As I typically commit before branching, it did not occur to me to look under the commit UI. Branching is still effectively undocumented even as of mid-2016; Chad Birch points out what passes for branching documentation; it's still awful, but as he notes, he's only the messenger...
  • Michael Tiller
    Michael Tiller over 14 years
    Ah, I see where it says "pressing this button opens up a branch maintenance dialog". That does indeed open a dialog that, as it turns out, allows branches to be created but I do take issue with the statement "As shown in the docs" since there is no explicit mention of how to create a branch anywhere on that page that I could find. I wonder what branching did to deserve getting second class treatment in TortoiseHg (vs. the other Tortoise* tools where it is a first class context menu option). :-)
  • Chad Birch
    Chad Birch over 14 years
    Oh, I wasn't trying to be insulting in a "RTFM" manner or anything like that, I just needed some sort of phrase to link to the relevant page with. Maybe "as vaguely implied in the docs" would have been more appropriate in this situation.
  • Michael Tiller
    Michael Tiller over 14 years
    No sweat. I wasn't trying to be insulting either. I just wanted to make it clear to anybody who came along to look at that link that you've really got to read between the lines in the docs to get the answer since it isn't explicitly mentioned.
  • Tower
    Tower over 13 years
    It's not convenient for feature branches.
  • blokeley
    blokeley over 13 years
    Agreed. If you have long-running (semi-permanent) branches, such as a version-1-stable branch and a version-2-stable branch, you'll want to use named branches. See also the mercurial branch documentation.
  • Peter Graham
    Peter Graham about 13 years
    -1. This is at best a hack. Cloning for branching doesn't work at all if you're following a remote repository, since you can't push your local changes. This means you can't share your branch with other developers you're working with. The correct way to branch is to create a named branch within your repository.
  • Peter Graham
    Peter Graham about 13 years
    With recent versions of Mercurial you need to do a hg push --new-branch to push a new branch to a remote repository. See stackoverflow.com/questions/2365483 for how to do this in TortoiseHg.
  • blokeley
    blokeley over 12 years
    Cloning is still how the official mercurial book recommends 'big picture' branches hgbook.red-bean.com/read/… Don't shoot the messenger.