Reputation:
Sorry for simple question but am new to git and feeling difficulty to solve my problem.
I have two branches parent
and child
. child
is created from parent
branch. I don't want to merge child
into parent
as of now. Instead of, shall i merge two branches by creating a new branch child-2
from parent
?
any help appreciate. thanks
Upvotes: 0
Views: 878
Reputation: 29546
I'm not sure what your use case is, but I'll try to clarify things up based on what they may be.
First, it is perfectly normal to have multiple "child" branches from a "parent". This is normally done to implement different features on separate branches or to separate the work to be done by multiple developers. You can merge any number of "child" branches later back to their "parent" branch.
Second, it is not always required to merge a branch back to its parent first before creating a new branch. You can always branch-out at any commit from the parent and you can also always merge them back at a convenient time (say for example, after a code review process is completed or after you've properly tested the code on that branch).
Based on your question, yes, it's fine to do this:
parent o -- o -- o -- -- -- -o -- --o --
\ \ / /
child-2 \ \- o -- o /
\ /
child \- o -- o -- o -- o --/
\
child-3 \-- o -- o -- -- -- -->
You can have a child
branch that you don't want to merge to parent
now, then you create a second child-2
branch, work on it, then merge them both later. I even added child-3
to show that it's not limited to just 2 branches.
However, there might be cases where you may need to merge child
first into parent
before creating new branches. This usually happens when child
has some critical/important changes that affects the development of subsequent branches, like for example, you changed your directory structure or changed the APIs on a base/common class or fixed an always-occurring bug. In those cases, it may be better to merge child
first before creating with new branches (OR you can also do a git rebase on child-2
, child-3
, etc. after merging child
, whichever will introduce the less conflicts).
Third, it is not required to merge a "child" branch to its "parent" (unless your team's/project's workflow/process requires you to). So, it's fine if you choose to merge child
and child-2
into some other branch temporary/test/integration branch first instead of directly into parent
.
So you can do this:
parent o -- o -- o -- -- -- -- -- -- -o
\ \ /
temp \ \-- -o-- -o- -o--/
\ / /
child \- o -- o --/ /
\ /
child-2 \-- o -- o --/
This is useful, for example, when you've got branches that introduce breaking changes or are interdependent, so you'd like to see how they work together first before merging it back to the main development branch. Again, you can have a child-3
, and so on there, as it's not limited to just 2 branches.
Upvotes: 2
Reputation: 357
Depends on what you want to achieve. Why do you want to create a new branch? What are you going to do with it? You could merge parent to child if you need to update your dev branch.
Upvotes: 0