Hi, Yep this can be an improvement that github can add. This can be currently done using github actions and proper branch protction rule. Lets say you want to make sure that example should be the only branch that is mergeable to master. You can do the following steps:
For pull requests
- Enable the branch protection rule for mater from repository settings > branches
- Enable the following checkbox:
This will make sure that the checks should be passing before someone can merge a PR.
- Add a github action (.github/workflows/merge-master.yam) with the following code:
- name: Check if the pull request is mergeable to master
if [[ "$GITHUB_HEAD_REF" == 'example' ]]; then exit 0; else exit 1; fi;
The above workflow will fail if the source branch is not example. Branch protection rule will prevent the pr from being merged to master.
For local git commit and merge
For this i recommend setting up a git hook on your local machine eg: Git hook to prevent merging staging branch into master branch - bl.ocks.org