Push rule public beta! #118843
Replies: 30 comments 75 replies
|
@patrick-knight Can these be used to enforce LFS on large files? Something like "if file extension is *.foo AND file size > 20MB AND file is not on LFS => deny"? From the screenshot, it looks like it may work, although it's ambiguous - if the file Can a rule be overridden by an admin on a case by case basis to push an exception to the rule? |
|
Awesome addition! |
|
I would like to prevent certain files, such as
Ideally, I would be able to say "do not allow adding matching files, but deleting is okay". |
|
Why is this availble only for private repos? As an open source maintainer, I'd like to be able to deny pushes with 10-mb binary files in PRs without having to manually inspect every part of one. |
|
I wanted to give feedback on a branch ruleset, but the "Give feedback" button opens this page... |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Excellent new feature, thank you for doing this. My first rule set was to restrict workflow changes, only allowing maintainer/admin roles in each repo to reduce the risk of malicious 3rd party actions being added accidentally. This is only a workaround though - I'd strongly prefer to have an org-level policy to only use the workflow that's in |
|
We set up a rule to prevent pushing We bumped into another issue with the same rule: even though set to evaluate, it resulted in workflows being unable to push commits to a third-party repository. We use fjogeleit/yaml-update-action to update a version in a YAML file. This step started failing with HttpError: Operation is blocked due to enforced push rulesets.Deleting the push rule, even though it was only in evaluation mode, made the issue go away. Blocking in eval-only mode seems to be a bug. We use a PAT to check out the repo and push to it, for what it's worth, and the bot user for which the PAT was generated has admin permissions on the repo; this lets the pushes override a "must create PR first" branch protection rule. |
|
Hi @patrick-knight, Using rulesets (and branch protection policies before that) we always faced a few issues while enforcing commit signatures.
Any of these situations will cause a (signed) merge commit on main to get blocked, because some of the baggage it's bringing along does not presently yield a valid signature. This new pre-receive enforcement seems like a great opportunity to address this use case. And BTW looking at the existing branch rulesets, enforcing commit metadata (ex: message patterns) does seem to follow the same kind of reasoning. Not that I have an immediate need for it, but it does make sense to me that it could be enforceable in the push phase as well. |
|
hey there, this is awesome feature, i tried to enable one, and bypass github app, but it doesnt seem work for the bypass, it still get the |
|
hi, Push Rules are a great idea, thank you for getting them this far. |
|
We use a tool called release-please on pushes to master which creates releases/tags based on semantic commits. Part of this involves updating the current version in We run the workflow as a dedicated GitHub App so I created the push ruleset with this App in the bypass list. The workflow cannot push a change to this file if the rulset is either active or evaluating, only disabled and nothing ever appears in the rule insights. I've confirmed with the Happy to provide more information if needed. |
|
Stumbled upon this (push ruleset) looking for a way to protect pipeline definitions. At a first glance seems to work as expected. And solves a real problem in a simple way that is otherwise hard to solve. π About this warning:
I get it (I think) but I can also imagine it complicating contributing by others. One more thought: When having enterprise plan, to what extent will it be possible to impose certain rules in bulk to all repositories? |
|
Thanks for this feature! As far as we could test, it perfectly fits our needs to protect our Workflows. |
|
Stumbled upon push rulesets when looking for a way to prevent changes to workflow definitions across all repos in an org. It also applies to public repos if you configure the rule on org level, but you can easily bypass the rule through a pull request. So pushing a change to a workflow directly to main is denied, but merging a PR with the same change from a fork is allowed, and it doesn't even appear in the Insights logs. I understand your concerns about open source forks and limiting this feature to push/PR merge for public repos might be a good middle ground. I'm curious about your thoughts on this. |
|
Encountered a couple issues when look to add a push ruleset to a repository. Would like to prevent most contributors from being able to modify certain files except for members of one team and a bot user. I can add both to by-pass the rule however when one of these restricted files has been updated on the main branch, anyone contributing changes via PRs that merges the updated main into their branch it will trigger the rule when they try to push it up. While we could ask people to rebase, this typically negatively impacts reviewing as once a review as begun rebasing means it's difficult for the review to see just what has changed since their last review. Additionally the second problem is that when developers hit this rule, there is no option to provide a customised message to help explain how to self resolve. Would it be possible to ignore commits containing changes to files that should be blocked if the commit is already part of the repository history? e.g.
The PR doesn't even show the file as being changed, it's only if you know how to use git diff to compare what was merged into the PR branch from the mainline that it is possible to see what triggered the failure. Even with such an exclusion, being able to customise the message for failures would be useful. We have a developer portal internally that teams can request changes that would result in generating the files that should not be pushed directly by them. This automatically ensures that the files have correct information that cannot be inferred by pipelines, so while we want developers to be able to trigger the creation of such protected files, we would want to tell them to use the portal instead of them hitting an error and then needing to ask for assistance. |
|
Restrict file size is awesome and has made life much better, but it would be nice to be able to allowlist specific files |
|
Please link to documentation (like in search) for the syntax allowed in globs: Context: I want to prevent recreating a deleted folder any of these could be valid, according to all the globbing variants out there:
but I don't know which of these will be correct. I found https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#restrict-file-paths, but I needed to search for 3 minutes to find this page, and then I'm redirected to a "technically correct", but not user friendly Ruby documentation. |
|
As a follow-up on glob docs comment, I tried
and it happily accepted my file: |
|
I really like how this feature is shaping up! We occasionally have the need for an admin to (force-)push to our protected |
|
Is it possible to allow files from the default branch to be compared against so when someone merges it into a feature branch the blocked file extensions can still be merged? Maybe compare the hash of the files in the default branch and the hash of the file in the commit and if they match allow it. |
|
It would be nice if this could be used to restrict merges to the target branches to a list of refs. For instance, if one were trying to enforce gitflow, being able to set something that only allows merges into main from develop. some option like "restrict source branch" |
|
Would love more flexibility in the rule sets. What we want: do not allow any updates to folder Currently, it seems like we can either (1) restrict any updates to folder Let me know if I'm missing something! One thing that would be very cool, especially considering that all GitHub users are developers, would be to let users define their protection rules in a simple DSL pushed to |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
We are running a classroom for which we would love to have an open template which is then forked privately in the course. Please reconsider if push rules for public repos would make sense. |
|
Any updates/ETA for when push rulesets will be available in public repos? |
|
How should by-pass reviewers determine what is in the commit flagged? Is this targeted for use with forks, where the bypass request reviewer can look at the commit in the contributors fork. Would be great if there was some way for bypass request reviewers to see what exactly they are approving when the push is being made directly. Maybe a downloadable artifact of the restricted path contents being pushed up that is kept only until the request is approved/rejected/timedout. |
|
Native Source β Target Branch Promotion Rules in GitHub Rulesets Problem GitHub Rulesets provide strong controls for protected branches, including pull-request requirements, reviews, status checks, deployments, and other merge policies. However, enterprise teams often need to enforce not only which branch is protected, but also where changes are allowed to come from. For example, a production promotion workflow may require: feature/* β dev β uat-aap β production The organization may want GitHub to enforce the following policy: production β uat-aap Β Β Β Allowed production β dev Β Β Β Β Β Blocked production β feature/* Β Β Blocked Today, this type of source-to-target relationship generally requires additional automation, such as a GitHub Actions workflow or an external policy engine. For enterprises where GitHub Actions are restricted or centrally controlled, relying on Actions for a fundamental repository governance policy creates an unnecessary dependency. Proposed capability Add a native Source Branch Restriction / Branch Promotion Rule to GitHub Rulesets. The rule would define a relationship between a target branch and its permitted source branches. Example:
When a pull request is opened, GitHub evaluates both: HEAD / Source branch Β Β Β Β + BASE / Target branch and determines whether the source β target relationship is permitted. Why this should be a Ruleset capability This is fundamentally a repository governance policy rather than a CI/CD job. Rulesets already provide the enforcement layer for branch-level governance. Source-to-target restrictions would extend the same model to policies that depend on both sides of a pull request. This would also avoid requiring organizations to create and maintain custom workflows solely to enforce branch promotion policies. Enterprise example An organization may define: feature/* Β Β Β β Β Β dev Β Β Β β Β uat-aap Β Β Β β production The Ruleset could enforce: Target: dev Allowed sources: Β feature/* Target: uat-aap Allowed sources: Β dev Target: production Allowed sources: Β uat-aap A pull request: uat-aap β production would be allowed, subject to the other configured rules. A pull request: dev β production would be rejected with a clear policy message: Source branch dev is not permitted to merge into target branch production. Allowed source branches: uat-aap. Important design considerations The feature should support:
Emergency changes The feature should also support controlled bypasses. For example: production β hotfix/* could be normally blocked while allowing an authorized team, role, or GitHub App to bypass the restriction under an organizationβs emergency-change policy. This avoids forcing enterprises to choose between strict promotion governance and the ability to handle production incidents. Why this is different from required status checks A status check can validate the source and target branches, but it treats the policy as a CI result. The proposed capability makes the relationship itself a first-class repository policy: Source branch + Target branch Β Β Β Β Β Β Β β Β Β Β Β Ruleset evaluation Β Β Β Β Β Β Β β Β Β Β Β Β Allow / Block That distinction is particularly valuable when GitHub Actions are unavailable or intentionally restricted. Broader use cases This capability would support more than a single GitFlow implementation. Examples include:
The goal is not to enforce one branching strategy. The goal is to make source-to-target branch relationships a first-class policy in GitHub Rulesets. |





Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We want to hear from you on push rules!
Who put an EXE file in my iOS mobile App repo? Why can I push a 20MiB mp3 when this repo is all .MD docs files? All these mysteries will soon be answerable and controllable.
It's been a year since we showed y'all the future of protecting branches with the public beta of repository rules.
But we had one lingering thought this whole time. How do we let you to prohibit certain things from entering a repository?
The repository rule release only let you protect refs, meaning the commit is in the repository already and can be reachable. Often, that's fine because rules are great for preventing unintended changes or enforcing governance decisions. But what about risky files in a repo due to size, type, or location? Thats where push rules come in.
If youβve had a chance to try out the repo rules that are now in public beta, weβre curious to know your thoughts and how we can make this feature work better for you!
π Known issues
~~ REST and GraphQL API will be available soon. ~~
When push rules are in- Fix rolled out Mayactiveorevaluatemode the usage of both the /git/trees and /git/blobs API endpoints are restricted.15th 2024
June 13th 2024 Update
REST and GraphQL endpoints are available for push rules
Added a delegated bypass flow to the beta to allow one time requests to skip push rules.
All reactions