2

I have a master branch and a feature branch. The feature branch has several changes but the master branch has many changes like removing 10 projects from the repository. The question is how to merge the feature branch back to master branch?

1) merge feature with master and then master with feature

OR

2) merge master with feature directly

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
mynkow
  • 4,408
  • 4
  • 38
  • 65

4 Answers4

2
checkout master
checkout -b develop (assuming you don't already have a develop branch)
merge --no-ff your-feature-branch

Resolve any conflicts in code. Test, test test.

checkout master
merge --no-ff develop

Then deploy your code.

I really like this branching model since it always keeps me building features on feature branches, doing final testing on develop. And only ever merging into master. No commits happen on master.

bryan kennedy
  • 6,969
  • 5
  • 43
  • 64
1

Don't do back merges. Integrate on an integration branch. Test completed branches on a release candidate branch. Only merge to master when you release a release candidate. You merge the release candidate that was deployed.

More on this here:

https://plus.google.com/109096274754593704906/posts/R4qkeyRadLR

UPDATE

I rewrote this here:

http://dymitruk.com/blog/2012/02/05/branch-per-feature/

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • well, we have a different approach for the whole picture. I just asked how to merge back 1 branch to master. I can say the same thing to bryan. I really like the branching model which you suggested but I am not able to apply it. – mynkow Feb 02 '12 at 19:57
  • Why would you not be able to apply it? – Adam Dymitruk Feb 02 '12 at 20:07
  • Many people in the company will be confused about that. I do not want to push them there right now. So, can you give me an advice 1) or 2). best regards – mynkow Feb 02 '12 at 21:35
  • I wouldn't do either. Start a new feature instead of merging master back into the feature. – Adam Dymitruk Feb 02 '12 at 22:19
-1

Both result in same state for master. Its just that feature branch is brought to same state as master in first case and remains unaffected in second case.

If you are asking which one to do, then doing the first is preferred way. You should merge master "into" feature first, so that any bugs after merging do not affect the master. Keeps the master clean. This also ensures that there are no merge conflicts in the master ever.

This is my general practice: Merge master into any feature branch and check that everything works fine. If something is broken, fix it. Then merge the latest master again. Only after the merged branch seems good, that this is put into master.

Sailesh
  • 25,517
  • 4
  • 34
  • 47
-1

I would rebase feature on top of master, then fast-forward feature on top of master

(with feature checkedout)

git rebase master
richo
  • 8,717
  • 3
  • 29
  • 47