Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rebasing dependent topic branches

Tags:

git

rebase

I use a lot of local topic branches in git, and sometimes end up with dependencies between topic branches causing rebase problems. For example, with a structure like:

master ---> featureA ---> featureB
                     \--> featureC

If master changes and I get (and resolve) conflicts when rebasing featureA, then afterwards rebasing featureB onto featureA triggers the same conflicts (and sometimes exciting new ones as well) because it tries to reapply the patches from the featureA branch. Assuming that the actual patches between featureA and featureB would apply cleanly if cherry-picked, is there a way of doing a rebase in this situation with roughly the same effect as cherry-picking all of the commits between featureA and featureB?

like image 632
Kai Avatar asked Oct 10 '09 00:10

Kai


People also ask

Should you rebase feature branches?

If the feature branch you are getting changes from is shared with other developers, rebasing is not recommended, because the rebasing process will create inconsistent repositories. For individuals, rebasing makes a lot of sense. If you want to see the history completely same as it happened, you should use merge.

When should you avoid rebasing a branch?

1 Answer. Show activity on this post. Case 1: We should not do Rebase on branch that is public, i.e. if you are not alone working on that branch and branch exists locally as well as remotely rebasing is not a good choice on such branches and it can cause bubble commits.

What does rebasing a branch mean?

From a content perspective, rebasing is changing the base of your branch from one commit to another making it appear as if you'd created your branch from a different commit. Internally, Git accomplishes this by creating new commits and applying them to the specified base.

Can you rebase a branch?

You can rebase your feature branch directly from the merge request through a quick action, if all of these conditions are met: No merge conflicts exist for your feature branch. You have the Developer role for the source project.

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.


Video Answer


1 Answers

After rebasing featureA, you can do

git rebase --onto featureA oldFeatureA featureB

assuming oldFeatureA represents the commit at the tip of featureA before you rebased it (you can either keep another branch there or just remember the commit hash).

This should basically be the same as cherry-picking each commit between A and B onto the rebased version of A.

Documentation on git-rebase (includes some helpful pictorial explanations of what happens during some more complex rebase operations)

like image 130
Phil Avatar answered Oct 21 '22 07:10

Phil