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?
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' ).
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.
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.
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.
git branch --format='%(refname:short)' --contains C | \ xargs -n 1 \ git rebase --committer-date-is-author-date --onto F C^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With