Git rebase when previous commit changed

Viewed 1772

I frequently find myself working on two different work tickets that are on different git branches, but one is dependent on another, like this:

* later-branch
|
* earlier-branch
|
* some prior commit
|

(Each is a single commit here because we are using gerrit, but this question might apply to multiple commits for each as well.) The earlier branch may be going through review, and so I might have to go back and modify it at some point with a git commit --amend. As must happen, this will fork the history:

* earlier-branch
|
|  * later-branch
|  |
|  * previous version of earlier-branch
| /
* some prior commit
|

At this point I want to rebase the later-branch on top of the new version of earlier-branch. But if I just do a git checkout later-branch followed by a git rebase earlier-branch, it always gets conflicts, because (I think) it must first apply the previous version of earlier-branch commit to the most recent version of earlier-branch.

What I end up doing is git checkout earlier-branch -b new-later-branch-name followed by git cherry-pick later-branch and git br -D later-branch. Which is a pain. Can anyone suggest a better way to handle this?

2 Answers
Related