Move branch to another branch

I have started doing some work on a branch which I have in term realised was the wrong branch. Is there a way to move a branch to a different branch.

For example:

A -- B -- C -- D -- HEAD \-- E -- F -- G -- H -- I -- J \-- K -- L 

And I want this:

A -- B -- C -- D -- HEAD \ \-- K -- L \ \-- E -- F -- G -- H -- I -- J 
1

3 Answers

Let's say you've named your branches like so:

 A -- B -- C -- D (master) \-- E -- G -- H -- I -- J (current-parent) \-- K -- L (my-branch) 

What you want to do is rebase my-branch onto the B commit like so:

 git rebase current-parent my-branch --onto B 
1

You could use git rebase --onto, e.g.,

git rebase --onto new-base old-base your-branch 

So in your case, something like:

git rebase --onto B E L 

should work.

1

This is just the sort of thing git rebase can do.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like