Search code examples
gitversion-controlbranchrebasegit-rebase

Rebasing a branch including all its children


I have the following Git repository topology:

A-B-F (master)
   \   D (feature-a)
    \ /
     C (feature)
      \
       E (feature-b)

By rebasing feature branch I expected to rebase the whole subtree (including child branches):

$ git rebase feature master

A-B-F (master)
     \   D (feature-a)
      \ /
       C (feature)
        \
         E (feature-b)

However, this is the actual result:

      C' (feature)
     /
A-B-F (master)
   \   D (feature-a)
    \ /
     C
      \
       E (feature-b)

I know I can easily fix it manually by executing:

$ git rebase --onto feature C feature-a
$ git rebase --onto feature C feature-b

But is there a way to automatically rebase branch including all its children/descendants?


Solution

  • git branch --format='%(refname:short)' --contains C | \
    xargs -n 1 \
    git rebase --committer-date-is-author-date --onto F C^