By default github provides three ways to merge a PR to a branch:
Can we add some branch rule or is there any way we can restrict them and allow only one or two options for any given branch.
Q4 2024: As confirmed by Patrick Knight (Product Manager at GitHub) in issue 10809
We've just shipped our initial version of this internally and are targeting a public preview next month.
Quick peek at where we are at on the UI front:
See also:
And yes, gh
CLI will be included:
Yes it will be in the ruleset API as property on the pull request object called "
allowed_merge_types
".See this example:
"type": "pull_request", "parameters": { "required_approving_review_count": 0, "dismiss_stale_reviews_on_push": false, "required_reviewers": [], "require_code_owner_review": false, "require_last_push_approval": false, "required_review_thread_resolution": false, "automatic_copilot_code_review_enabled": false, "allowed_merge_types": [ "squash", "merge", "rebase" ] } } ],```
Q3 2024: While discussion 10809 is still not supported, there are some evolutions:
On the second point, Dhiraj Sharma proposes the following:
I know it's better to have this feature in the backend, but for anyone okay with a frontend solution to avoid mistakes when merging PRs, I've built an extension.
I use squash for all branches except when merging into master, but occasionally, I make mistakes in the process.The extension lets you customize settings for repos, source/destination branches, and merge options. Feel free to check it out, and I'd appreciate any feedback or suggestions!