Updating Stacked Pull Requests with git rebase --onto
13 points by BD103
13 points by BD103
If you have stacked branches, it is sometimes easier to perform e.g. a fixup commit referencing any of the older commits while being on the tip of the branches, then using --update-refs on git rebase to make git automatically update all of the intermediate branches. This prints an update-ref command in the interactive rebase command list, which you can also use to toss commits over between the intermediate branches. Then you can git push --force-with-lease intermediate-branch-1 intermediate-branch-2 tip-branch to push the whole stack.
You can use this to rebase the entire stack to main at once without having to rebase the individual intermediates.
Whoa, I've read about this a couple of times, but never got round to testing it out.
Quiet Friday Afternoon here and I decided to test it, very nice!
I'm in the curious situation that 40% of my team is on jj, I'm on Git along with the other 50% of the team.
I don't migrate to jj because many of the things it automates I do without thinking. And now that I learned rebase -i --update-refs, I have even less reasons to learn a new and useful thing.
And... I can't really share this with anyone on the team. It will be terribly uninteresting to the jj users, and the Git users are mostly those who really don't rewrite history.
Mandatory recommendation of Jujutsu, which solves this problem by default: https://docs.jj-vcs.dev/latest/
I'd also like to mention Mercurial, which Jujutsu probably takes inspiration from. The changeset evolution feature (from hg-evolve extension) makes it possible to store orphaned and rewritten commits from every contributor in the repository, then when using the hg evolve command it will automatically rebase your own revisions.
I don't recommend using Mercurial but this feature makes rewriting the history a lot easier and less error-prone (at the cost of storing more data on the server).
Might have to check Jujutsu since everyone talks about it, though 😀