14
votes

I have a central repo and a local repo. The repo has the "default" branch and one named branch "mybranch". If I am working in the named branch and want to occasionally merge my changes into default and then continue working in the named branch should I do this:

  1. pull latest from central repo into my local repo
  2. while working in mybranch, do a "hg merge default" to merge default INTO mybranch
  3. commit locally
  4. then do "hg update default" and "hg merge mybranch" to merge mybranch INTO default
  5. commit locally
  6. push to the central repo e OR

do same as above, but switch #2 with #4? (so that I am merging mybranch INTO default first?

2

2 Answers

15
votes

You write that you

want to occasionally merge my changes into default and then continue working in the named branch

You should normally not merge the feature branch into the default branch, unless the feature is done. Maybe that is what you meant?

Just for reference, the recommended workflow is to do

  1. Create feature branch
  2. Do your work there
  3. Regularly (every couple of days) merge changes from default into the feature branch:

    1. hg pull to get the latest changes from the other developers
    2. hg merge to integrate the latest changes into your feature branch
  4. When the feature branch is all done, you merge it back into default:

    1. hg pull
    2. hg update default to checkout the branch you want to merge into
    3. hg merge myfeature to do the merge

The final merge will be very small since the regular merges of default into the feature branch makes sure that there is only a small distance from the two branch heads back to a common ancestor.

8
votes

The way you have it now (merge default into mybranch first) is my preferred way.

I tend to use branches for isolating changes for a particular feature or refactoring, so it's best to bring changesets from default into the named branch at regular intervals. This way the named branch's changes are kept up-to-date in relation to the default branch.