Search code examples
gitgithubversion-control

Why would you ever do squash and merge on master when using GitFlow?


Our team has been using squash and merge religiously for the last two months as we heard it was best practice. But recently it was discovered that we were using it incorrectly.

Initially, I thought squash-and-merge just created a neat little wrapper commit for the commits in your merge but that is NOT the case. It creates a separate, unrelated commit. Therefore, after two months, even though our files were in sync between our 'develop' and 'master' branches, the commits were not -- so our PRs showed the entire set of changes that had been implemented during that time period. Needless to say, it was impossible to look at.

We resolved it by doing a rebase on 'develop' and release branches (which was SUCH a nightmare) and then, to make sure it didn't happen again, looked for a setting or configuration in our GitHub admin settings to disallow squash-and-merge on master but couldn't find one.

Given that that setting doesn't exist, my questions are this: If you are using GitFlow, would there ever be use case for squash-and-merging to 'master'? Seems like it's a function that should only be used between a non-permanent branch and a permanent one, and never between two permanent branches. If so, are there are steps or configurations you need so your branches don't get out of sync?


Solution

  • If you are using GitFlow, would there ever be use case for squash-and-merging to 'master'?

    No, you should never squash-and-merge your release branches or hotfixes into master.

    Seems like it's a function that should only be used between a non-permanent branch and a permanent one, and never between two permanent branches

    Exactly right. You use it to merge a branch that you intend to delete, where you specifically don't intend to keep its history around. It's purposefully destructive, collapsing the whole branch down to a single commit on the destination branch. When you are done with a squash-and-merge, it will appear as though the work was done in a single commit directly on the destination branch.

    Squash-and-merge is mostly for trunk-based development, where you continually merge small throw-away branches into a main branch.

    If so, are there are steps or configurations you need so your branches don't get out of sync?

    No. Git-flow works fine, just don't squash-and-merge things you want to keep around.