Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge features branches to branch develop in Git?

I am new to Git and I have a simple question

Though this has been asked many times in this forum, I want to restrict my question to the following scenario

1)  Feature A  (Files A, B and C were modified) cut from 'develop'
2)  Feature B  (Files A and D were modified) cut from 'develop'

Feature A has been merged into branch 'develop' successfully

Now the question is, what approach should we follow to merge 'Feature B' to branch 'develop'

Should we pull the latest version of 'develop' and merge the changes of 'feature b' (or) What other best approaches to merge 'feature b' to 'develop' so that 'File A' has all the changes?

like image 811
Sathish Kumar Avatar asked Aug 25 '15 04:08

Sathish Kumar


2 Answers

Let us say that you are not going to have conflicts among your merges/rebases and you work locally (no fetches/pulls/pushes) for the sake of simplicity.

There are basically two ways to proceed. Merging or rebasing. Both get the same result. You decide depending on your work policy.

You can merge:

                     //      C3-C4
git checkout develop //     /     \
git merge featureB   // C1-C2--C5--C6

Or you can rebase:

                       //      C3-C4
git checkout featureB  //     /
git rebase develop     // C1-C2--C5--C3'--C4'

The code in the commit C6 and C4' is the same.

If you use the policy of "merging" you can see with a GUI (e.g. gitk) the different features that you were doing quickly.

If you use the policy of "rebasing" you can follow easier the evolution of your proyect when you use commands like git log

like image 164
blashser Avatar answered Oct 05 '22 13:10

blashser


If you are alone working on FeatureB branch, the a pull --rebase develop is the best practice: you are replaying FeatureB changes on top of FeatureA. (and git push --force after).

If you are multiple developers working on FeatureB, then a merge of develop to FeatureB has to be done, before merging FeatureB to develop.

In both cases, the idea is the same: test the integration of both features locally (pull or rebase), before merging back to develop.

Do not merge to develop first, "hoping" that the result (on develop) is "good enough".

like image 23
VonC Avatar answered Oct 05 '22 13:10

VonC