Reputation: 1324
I'm working on branch C which is based on branch B, then branch A:
A---B---C
Is there any commands that can make branch C directly based on branch A like this:
A---B
\
--C
I have tried git rebase A
but it does not work.
Upvotes: 2
Views: 750
Reputation: 40066
git rebase --onto A B C
Explanation:
In rebase command, you can define:
and the command is
git rebase --onto TargetBranchToRebaseTo UpstreamBranch BranchToRebase
In fact you can almost an exact example in git help rebase
Upvotes: 2
Reputation: 76904
Git has a builtin option to rebase
that does just that:
git checkout C
git rebase --onto A B
This rebases all of the commits after B up to C such that they start on A instead of B.
Upvotes: 0
Reputation: 12591
Here's what I would do:
git checkout C
git checkout -b rebaseTemp
git rebase -i A
In the interactive rebase, delete all of the commits that correspond to branch B, but aren't a part of branch C (i.e. the commits that are shared between the two). Complete the rebase, then you will have a new branch (rebaseTemp) that contains what I think you want. You can then merge A into rebaseTemp (which will result in a fast-forward merge).
A branch visualization tool (i.e. gitk
) is really useful for this scenario, so you can see what commits are shared.
Upvotes: 0