You should use git rebase --onto

What's it for?

At its core a rebase onto operation is used for moving commits from a specific parent commit to a new specific parent commit.

Typical situations this may be useful include:

Usage

git rebase --onto newbase oldbase

Note that the newbase and oldbase arguments are reversed from a typical "source -> destination" argument order.

If you currently have a remote branch, you will need to force push your changes onto it after running this command.

Examples

To move your branch's base to be master from oldbranch.

git rebase --onto origin/master oldbranch

To move your branch's base to be master from af893ea (where af893ea is the commit just before your work).

git rebase --onto origin/master af893ea

To move your branch's base to be the commit eb3a99f from af893ea (where af893ea is the commit just before your work).

git rebase --onto eb3a99f af893ea

After resolving any conflicts, force push your changes to your remote branch if it exists.