Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should one merge a named branch into the default branch first or vice-versa?

Tags:

mercurial

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?

like image 418
BestPractices Avatar asked Dec 08 '11 14:12

BestPractices


People also ask

Does it matter which way you merge in Git?

Usually it does not matter if both branches are topic or feature branches. However, if you have an integration branch or a branch that marks what's been published, you definitely want to use the long lived integration branch as the one that's checked out and merge the other one into it.

Can you merge a branch that is behind Master?

If the developer wants to merge master into a branch that's protected, they must perform a GitLab merge request. If the developer wants to merge master into a branch that's unprotected, the easiest approach is to do a merge and push combination on the client machine.

Can I merge a branch again?

Ideally, we would take all the changes in C*, apply them to master and resolve all conflicts. But because the branches have already been merged, git doesn't detect any changes and won't allow to merge again.


2 Answers

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.

like image 166
Martin Geisler Avatar answered Sep 18 '22 17:09

Martin Geisler


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.

like image 33
Joel B Fant Avatar answered Sep 20 '22 17:09

Joel B Fant