I'm quite new to git and I'm not sure if it's a dumb question.
Currently I'm working on feature_1 branch up to date with the master, and I want to merge it with feature_2 branch which is many commits behind the master. What is the best way to do so?
My thought is to first checkout to feature_2 branch and merge with the master. Then checkout to feature_1 branch and merge with feature_2 branch?
CodePudding user response:
In general, you should not merge a feature branch into another feature branch. Instead you should finish feature_1
and merge it into master
. Then just delete feature_1
. Now when you continue work on feature_2
, just merge master
into it.
CodePudding user response:
Let's try to answer your question using an illustration showcasing what you are describing.
It's important to understand that merge
intertwines histories together, but just like Romain Valeri mentions in his comment to your question, there's always a receiving end. In your case, either feature-1 get's the changes present in feature-2, or feature-2 gets all changes currently present in feature-1/master.
HEAD
illustrates which branch is currently checked out, and in this case works as the receiving end when merge
is invoked.
A final note: merging feature branches back-and-forth is generally bad practice. Try to keep them isolated and only integrate changes once they have been merged with master
(or which ever branch you are using as your main branch). Once a branch has been merged into master
it should generally be deleted.