Feature Request: Restrict source branches in Repository Rulesets (e.g., only allow 'develop' to merge into 'main') #208945
Replies: 3 comments
|
💬 Your Product Feedback Has Been Submitted 🎉 Thank you for taking the time to share your insights with us! Your feedback is invaluable as we build a better GitHub experience for all our users. Here's what you can expect moving forward ⏩
Where to look to see what's shipping 👀
What you can do in the meantime 💻
As a member of the GitHub community, your participation is essential. While we can't promise that every suggestion will be implemented, we want to emphasize that your feedback is instrumental in guiding our decisions and priorities. Thank you once again for your contribution to making GitHub even better! We're grateful for your ongoing support and collaboration in shaping the future of our platform. ⭐ |
|
+1 for native support. For anyone who needs the workaround today, there are two details that make it airtight: name: pr-source-guard
on:
pull_request:
branches: [main]
types: [opened, reopened, synchronize, edited] # 'edited' catches retargeting a PR to main
jobs:
source-branch:
runs-on: ubuntu-latest
steps:
- if: github.head_ref != 'develop' || github.event.pull_request.head.repo.full_name != github.repository
env:
HEAD: ${{ github.event.pull_request.head.repo.full_name }}:${{ github.head_ref }}
run: |
echo "::error::PRs into main must come from develop in this repo (got $HEAD)"
exit 1Checking |
|
+1 for native support too. Two additions for anyone rolling this out at org scale:
The workflow approach remains the best available today; these two points just close the gaps that tend to appear once you scale it past a single repo. |
Uh oh!
There was an error while loading. Please reload this page.
🏷️ Discussion Type
Product Feedback
Body
The Problem
When managing an organization repository with multiple collaborators, we often enforce strict Git workflows, such as:
other-branches➔ Normal Merge ➔develop➔ Squash Merge ➔mainTo enforce this, we configure a Repository Ruleset targeting the
mainbranch, enablingRequire a pull request before mergingand restricting the allowed merge methods strictly toAllow squash merging.However, there is a security loophole: GitHub currently does not provide a native option within Rulesets to restrict the source branch of a Pull Request. This means that while direct commits to
mainare blocked, any user can still accidentally or intentionally open a Pull Request from a randomfeature-branchstraight intomainand bypass thedevelopbranch entirely.The Proposed Solution
It would be incredibly helpful if GitHub added a new rule inside the Repository Rulesets configuration (specifically under the
Require a pull request before mergingsection or as a standalone branch rule) to restrict or whitelist allowed source branches.Ideally, when setting up a rule for a target branch (e.g.,
main), we should be able to configure:develop) that are permitted to target this branch in a Pull Request. All other source branches would be blocked automatically by the platform UI.Current Workaround
Right now, the only way to achieve this behavior is by writing custom GitHub Actions workflows to validate the
github.head_refand enforcing them viaRequire status checks to pass. Having this natively built into Repository Rulesets would make organization management much cleaner, more secure, and easier to scale.All reactions