Improvement suggestion settings -> branch -pattern that can only merge to target branch(pattern)

Hello I have a couple suggestions. Not certain if these have been suggested yet. I don’t see it in the community.

A way to restrict which branches can be merged into a specific branch. Also making the delete head branches after pr merge specific to a branch.

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

  1. Enable the branch protection rule for mater from repository settings > branches
  2. Enable the following checkbox:

    This will make sure that the checks should be passing before someone can merge a PR.
  3. Add a github action (.github/workflows/merge-master.yam) with the following code:
on:
  pull_request:
    branches:
      - master
jobs:
    merge_check:
    runs-on: ubuntu-latest
    steps:
      -  name: Check if the pull request is mergeable to master
          run: |
               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