Reputation: 1526
Have following branches structure:
master
/ \
BranchA BranchB
But it should be:
master
/
BranchA
/
BranchB
Could anyone advice how to re-hang BranchB as child of BranchA?
Upvotes: 39
Views: 26032
Reputation: 12728
I suggest using git rebase -i
(interactive mode) to edit the whole history, which commit you want as the starting point of new branch rebase, the commit message, etc.
In your case, if you desired situation is:
master
/
BranchA
/
BranchB
but on branchA you already have some commits:
master
/
BranchA
|
commit A1
|
commit A2
You may want to choose the A1 as starting point of branchB, not A2(the latest, where the HEAD of A is), then git rebase -i
can help.
Upvotes: 1
Reputation: 968
git checkout branchB; git rebase branchA;
will do this for you. bear in mind if this has been pushed somewhere else, you'll screw up the history.
Upvotes: 7
Reputation: 9851
You want to use rebase. With BranchB checked-out, do
git rebase BranchA
Upvotes: 47