Search code examples
gitgithubgit-mergepull-requestgit-squash

GitHub Pull Request: Squash before merge without fast-forward


GitHub offers three options to merge PRs:

  1. Merge pull request: No fast-forward merge.
  2. Squash and merge: Squash commits and perform fast-forward merge.
  3. Rebase and merge: Rebases all commits onto the other one.

Is it somehow possible to automatically squash the commits before merge and then apply the merge without fast-forwarding it?

One option is of course to squash them before merging manually and then use option 1, but doing it that way it cannot be forced and the PR needs to be reviewed again and the merge is blocked until it is approved.


Solution

  • If the policy is that every PR is to consist of just one commit, then squashing before doing a (normal) merge is fine, even with a forced push. Personally I think that's a bit silly; history is history, and I don't see what's gained by pretending it isn't. But chacun à son goût.

    and the PR needs to be reviewed again and the merge is blocked until it is approved.

    But then there's your problem. If GitHub is removing the ability to merge after the PR was approved, merely because you did a new push into the PR branch, and you don't like that, then your GitHub action settings are wrong for your workflow. Change them.

    (In our workflow, for example, once approved always approved; new commits don't require reapproving (though of course you can ask for reapproval as a double-check).)