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.
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
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.