Is there any way to replace merge with rebase at GitHub PRs? I looked through protected branches settings but didn't find such option.

GitHub now (Feb. 2022) supports this (*: caveat, see discussion 12032, detailed at the end):
More ways to keep your pull request branch up-to-date
The Update branch button on the pull request page lets you update your pull request's branch with the latest changes from the base branch.
This is useful for verifying your changes are compatible with the current version of the base branch before you merge.Update your pull request branch by rebasing:
When your pull request's branch is out of date with the base branch, you now have the option to update it by rebasing on the latest version of the base branch.
Rebasing applies the changes from your branch onto the latest version of the base branch, resulting in a branch with a linear history since no merge commit is created.
To update by rebasing, click the drop down menu next to the
Update Branchbutton, clickUpdate with rebase, and then clickRebase branch.Previously, Update branch performed a traditional merge that always resulted in a merge commit in your pull request branch. This option is still available, but now you have the choice.
Note: Because rebasing rewrites the history of the branch, if you are working with the branch locally, you will need to fetch it and do a hard reset to ensure your local branch matches the branch on GitHub.com.
Learn more about keeping your pull request in sync with the base branch.
Note: Feb. 2022 discussion 12032 from Feb. 2022 asks (author: Valentin Agachi):
The new update branch feature is great!
But for teams which are only using the rebase functionality, it's not optimal to always have to pick the rebase option from a drop down menu.
It would be ideal if there were a repository level setting to configure which option is the default for that button.
Another user, Waleed Ashraf confirms more than 2 years later (Sept. 2024, emphasis mine):
Response from GitHub support as of today,
Currently, "
Update with rebase" as the default when updating a branch from the main branch option is not available.We have however heard this request from other customers as well.
I have gone ahead and added your voice to our internal issue tracking this feature.
I can not say if or when this feature might be added, but we'll make sure to document it in the GitHub Changelog or the GitHub Blog if it becomes available.
IMPORTANT: The recommendation below will not work if main contains any merge commits. :(
NOTE: With the recommendation below, a GitHub bug causes "Rebase branch" to be initially displayed as "Update branch". Refreshing the PR page will show "Rebase branch" and is required to perform a rebase. :(
This is now supported by Github by enforcing a linear branch history for all branches (see reference). Steps:
Open repository Settings
Rules → Rulesets
New Ruleset → New Branch Ruleset
Ruleset Name: “Linear History”
Enforcement Status: Active
Add Target → Include all branches
Branchset rules → Require linear history (only)
Create
The default when a GitHub branch is out of date should now be "Rebase branch" (requires page refresh as per note above).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With