Search code examples
gitgit-mergesquashgit-squash

merging from one feature branch to another after squashes


My team likes to have a "clean" git history, and likes commits to be squashed before I request a code review. One aspect of this workflow I'm having trouble with:

I want to work on feature-branch-2 (which depends on the stuff in feature-branch-1) while feature-branch-1 is under review. So:

git checkout -b feature-branch-2 feature-branch

Add some commits to feature-branch-2 while I work.

Code review comments come back, so I add some commits to feature-branch-1 that respond to them. Then I squash those commits, and post again for review.

But now I've got a problem: How do I easily bring feature-branch-2 up-to-date with the fixes to feature-branch-1? This would be an easy merge if I hadn't squashed feature-branch-1's commits, but I'm not sure what's an easy workflow with the squashes.


Solution

  • Since you are rewriting history by squashing, thereby removing the parent commit of your feature-branch-2, the only way I can think of is to rebase. After feature-branch-1 is updated you can do.

    git checkout feature-branch-2
    git rebase feature-branch-1