I often have sub-branches on a branch that I want to rebase onto the mainline. Consider this:
* (Mainline)
*
*
| * (topicA_Branch3)
| *
| *
| * (topicA_Branch2)
| *
| *
| * (topicA_Branch1)
| *
| *
|/
*
*
I want to move all three of these topicA
branches onto mainline. Currently, I know two ways to do this:
While on topicA_Branch3
, execute the command, git rebase Mainline
.
a. At this point, I would have to delete topicA_Branch1
and 2
and manually re-create the branches on the correct commits on the now rebased topicA_Branch3
.
Another way would be to do three separate commands:
a. While on topicA_Branch1
, do git rebase Mainline
.
b. git rebase --onto topicABranch1 <topicA_Branch1-old-SHA> topicABranch2
c. git rebase --onto topicABranch2 <topicA_Branch2-old-SHA> topicABranch3
d. This is kind of cumbersome...
Is there a command that I want that will rebase a branch and bring it's sub-branches with it?
To be clear, I want to end up with this:
* (topicA_Branch3)
*
*
* (topicA_Branch2)
*
*
* (topicA_Branch1)
*
*
* (Mainline)
*
*
*
*
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.
Yes, you can rebase more than once. After rebasing, you get a fresh set of commits. These commits are exactly like all other commits and hold no record of having been rebased. The main thing you need to be careful for is the possibility of rebase conflicts.
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.
Unlike a merge, which merges two branches in one go, rebasing applies the changes from one branch one by one.
What about that:
a. While on `topicA_Branch1`, do `git rebase Mainline`.
b. `git rebase --onto topicABranch1 topicABranch1@{1} topicABranch2`
c. `git rebase --onto topicABranch2 topicABranch2@{1} topicABranch3`
d. ...
This might easily be automated. The syntax topicABranch1@{1} means "the last known state of topicABranch1 before the rebase"
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