Noa
Noa

Reputation: 355

git change the parent branch

The short story is : I have created Branch A out from the Develop Branch then I created Branch B From Branch A

We decided later that we need to include the branch B in the next release and A will not be included

what I am planning to do is :

  1. delete my First pull request for B
  2. create a new branch B1 from Develop branch
  3. cherry-pick the commits I need
  4. then delete the old B branch
  5. rename B1 to be B
  6. create a Pull Request for the new Branch B

so I was thinking if there is a way to change the parent of B branch to be Develop instead of A to avoid this mess

Upvotes: 1

Views: 1193

Answers (2)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521194

Let's say that your current branch diagram looks something like this:

develop: A -- B
               \
branchA:        C -- D -- E
                           \
branchB:                    F -- G

You want the B branch to look like this:

develop: A -- B
               \
branchB:        F -- G

Rebase onto can be used here:

git rebase --onto B E

In plain English terms, the above command says to place the commit whose parent is E, which is the F commit (and the start of the B branch) onto a new base which is commit B in the develop branch.

Upvotes: 3

kowsky
kowsky

Reputation: 14459

You are looking for git rebase --onto, since what you want to do is basically rebase only the commits from branch B onto develop.

There is a very good description of rebasing in the official git documentation. See section More Interesting Rebases for an example like yours.

Your example would be solved by git rebase --onto develop branchA branchB.

Also see the git rebase documentation.

Upvotes: 2

Related Questions