Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change branch parent

Tags:

git

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?

like image 462
Ivan Avatar asked Nov 05 '12 15:11

Ivan


People also ask

How do I change my parent branch?

We can create a new branch with parent master branch and use git cherry-pick command to move each commit from one branch to another. This solution is OK, when you don't have many commits, because for each commit you need to do git cherry-pick .

How do I know the parent branch in git?

Run the command git parent . That's it!

What happens if I delete parent branch?

What happens? nothing. If you create a branch where another is, you can "delete" that other branch without losing anything. A branch (HEAD) is just a pointer to a commit.


2 Answers

You want to use rebase. With BranchB checked-out, do

git rebase BranchA 
like image 171
Wesley Wiser Avatar answered Oct 02 '22 16:10

Wesley Wiser


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.

like image 40
Michael Avatar answered Oct 02 '22 18:10

Michael