Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 443
Tomasz Nurkiewicz Avatar asked Apr 08 '11 20:04

Tomasz Nurkiewicz


People also ask

How do you rebase a child branch with the parent branch?

The solution is to use git rebase --onto after rebasing the first branch. This will rebase all commits of feature2 that follow the old head of feature1 (i.e. F ) onto the new head of feature1 (i.e. F' ).

What does rebasing a branch do?

Rebase is another way to integrate changes from one branch to another. Rebase compresses all the changes into a single “patch.” Then it integrates the patch onto the target branch. Unlike merging, rebasing flattens the history because it transfers the completed work from one branch to another.

What is the golden rule of rebasing?

The Golden Rule of Rebasing reads: “Never rebase while you're on a public branch.” This way, no one else will be pushing other changes, and no commits that aren't in your local repo will exist on the remote branch.

How do I rebase an existing branch?

In the Branches popup or in the Branches pane of the Git tool window select a branch and choose one of the following actions: Pull into Current Using Rebase (for remote branches) to fetch changes from the selected branch and rebase the current branch on top of these changes.


1 Answers

git branch --format='%(refname:short)' --contains C | \ xargs -n 1 \ git rebase --committer-date-is-author-date --onto F C^ 
like image 194
Adam Dymitruk Avatar answered Sep 22 '22 02:09

Adam Dymitruk