Slartibartfast
Slartibartfast

Reputation: 611

Rebase a series of branches into parallel Branches

I frequently end up with a series of branches built one from the other like this:

...-(M)
     |
     +-A
       |
       +-B
         |
         +-C

Usually with pull-requests for each of A, B and C.

The issue is that if I request a Pull request from C it includes all the changes made in the branches A and B, which just irritates people.

I would like to re-structure the graph such that it looks like:

...-(M)
     |
     +-A
     |
     +-B
     |
     +-C

But each time I attempt to rebase either 'B' or 'C' onto '(M)' the structure remains the same.

What would be the correct way to restructure this?

By the way, I use SourceTree for all my Git-related needs but am happy to translate from console instructions if necessary.

Edit: The solution suggested by VonC did indeed work however it would not work for me while I was using SourceTree's builtin version of Git. After downloading a portable version from here: https://github.com/git-for-windows/git/releases/tag/v2.14.2.windows.3 it worked fine.

Upvotes: 2

Views: 290

Answers (1)

VonC
VonC

Reputation: 1330002

Any rebase which does not involve all the previous commits is a rebase --onto command.

git checkout C
git rebase --onto M B C

That means: rebase everything after B (B excluded) up to C (C included) onto M.

git checkout B
git rebase --onto M A B

Note: for that, it is best to use the git bash of the latest Git for Windows (like PortableGit-2.14.2.3-64-bit.7z.exe unzipped anywhere you want). That will avoid weird bugs like "There is no tracking information for the current branch. Please specify which branch you want to rebase against." that I mentionned here.
A rebase is a local operation, and should not be concerned with remote branches.

Upvotes: 2

Related Questions