M Kenyon II M Kenyon II - 4 months ago 17
Git Question

Can I change which branch a Git branch stems from?

In our project we have a develop branch, and whenever working on an issue, we branch from develop to item-xxxx and do our work there.

It seems that

item-0012
was branched off a commit from
item-0009
instead of the
develop
branch and pushed. So, a merge of
item-0012
back into develop would include changes for both branches.

Is there a way to get
item-0012
to go back to being branched off
develop
? There were no changes made in
item-0009
needed by
item-0012
.

Sorry if I'm missing the terms, still wrapping my head around Git.

Right now Git looks something like this with
item-0012
branched off of commit (c17) of the
item-0009
branch:

develop-(c14)-(c16)-(c18)

____\item-0009-(c15)-(c17)

____________________ \item-0012-(c20)

I would like the
item-0012
branch to stem off of commit (c16):

develop-(c14)-(c16)-(c18)

_____________ \item-0012-(c20)

Is this possible?

Answer

Have you tried to rebase your item-0012 onto develop? From rebase docs:

   Here is how you would transplant a topic branch based on one branch to another, to pretend that you forked the topic branch from the latter branch,
   using rebase --onto.

   First let's assume your topic is based on branch next. For example, a feature developed in topic depends on some functionality which is found in next.

           o---o---o---o---o  master
                \
                 o---o---o---o---o  next
                                  \
                                   o---o---o  topic

   We want to make topic forked from branch master; for example, because the functionality on which topic depends was merged into the more stable master
   branch. We want our tree to look like this:

           o---o---o---o---o  master
               |            \
               |             o'--o'--o'  topic
                \
                 o---o---o---o---o  next

   We can get this using the following command:

       git rebase --onto master next topic

You should git rebase --onto develop item-0009 item-0012