Rebasing a branch including all its children

Tomasz Nurkiewicz picture Tomasz Nurkiewicz · Apr 8, 2011 · Viewed 12.1k times · Source

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?

Answer

Adam Dymitruk picture Adam Dymitruk · Apr 12, 2011
git branch --format='%(refname:short)' --contains C | \
xargs -n 1 \
git rebase --committer-date-is-author-date --onto F C^