Context
On GitLab, a CI job can block an unsquashed MR by reading CI_MERGE_REQUEST_SQUASH_ON_MERGE .
On GitHub, the same approach is not possible: there is no "squash" checkbox on the PR .
The merge method (Merge commit, Squash, Rebase) is chosen when clicking the button, after CI has run.
There are two approaches.
Option 1 β Ruleset: squash only on develop
Settings β General β Pull Requests : keep Allow squash merging and Allow merge commits enabled (the repository settings are the master switch; a ruleset can only restrict further).
Settings β Rules β Rulesets β New branch ruleset :
Target: develop
Enable Require a pull request before merging
Allowed merge methods : Squash only
main / master : no restriction (or a separate ruleset) to keep merge commits for release PRs.
β
No code, no effort for developers; applies to both the UI and the API.
β οΈ Some users report that the rule is not always enforced when the repository allows several methods.β¦