Learning center

When should a push ruleset block files before review sees them?

Use push rules for files that must never enter the repository on any branch. Binaries, oversized files and paths few people may change are typical. The rules check every commit in a push, so they stop a file that a branch adds and then deletes. They are available for private and internal repositories on GitHub Team and GitHub Enterprise Cloud.

What push rules check#

A push ruleset applies "to every push to the repository" with no branch targeting, and covers "that repository's entire fork network." It can restrict file paths, file path length, file extensions and file size. Push rulesets The rule definitions are written per commit: Restrict file paths will "Prevent commits that include changes in specified file paths from being pushed," and Restrict file size will "Prevent commits that exceed a specified file size limit from being pushed." Available rules for rulesets

Path and extension lists are limited to 200 entries of up to 200 characters each, and paths use fnmatch syntax. Restrict file paths and Restrict file size accept allowed exceptions, which GitHub introduced as a public preview in August 2026. GitHub changelog, 25 August 2026 The REST API notes that the size limit "does not apply to Git Large File Storage (Git LFS)." Create a repository ruleset

The rules also cover more than git push. They apply to the REST API's "Create a blob", "Create a tree" and "Create or update file contents" endpoints, and a push may carry at most 1,000 reference updates. Troubleshooting rules Bypass works as for other rulesets, except that the root repository's bypass list governs every fork.

On GitHub.com, the documentation states the plan condition: "Push rulesets are available for the GitHub Team plan in internal and private repositories, and forks of repositories that have push rulesets enabled." Creating a push ruleset GitHub Enterprise Cloud customers can also set them on internal repositories and across organizations. GitHub changelog, 10 September 2024 Public repositories cannot use them.

What review misses that a push rule catches#

Reviewers read a pull request's diff, which compares the branch's final state with its base. A file added in one commit and removed in a later one does not appear in that diff, yet both commits enter the repository when the branch is pushed. If the pull request is merged with a merge commit or a rebase merge, the file also stays in the default branch's history.

This local run, in a throwaway repository, shows the gap in Git itself. A branch adds a 30 MB data file with a code change, then removes the file:

$ git diff --stat main...add-report
 app.py | 1 +
 1 file changed, 1 insertion(+)
$ git log --stat --format=%s main..add-report
Remove sample data

 dump.bin | Bin 30000000 -> 0 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
Add report and sample data

 app.py   |   1 +
 dump.bin | Bin 0 -> 30000000 bytes
 2 files changed, 1 insertion(+)
$ git gc -q && git count-objects -vH | grep size-pack
size-pack: 28.62 MiB

The three-dot diff, which is what a reviewer reads, shows a one-line change. The history carries the 30 MB file, and so does the object store. CI sees the same final tree as the reviewer, so a check on the pull request's state would not object either. A push rule that limits file size evaluates the commits being pushed, so the push carrying "Add report and sample data" is refused before any of it reaches GitHub. The same applies to a binary added under a restricted extension and to a commit touching a restricted path.

Removing a file from history after it lands takes a rewrite and a force push, and with force pushes blocked on the default branch, a bypass. Stopping it at push time is cheaper.

A worked configuration#

Suppose a fictional private repository, acme/payments-api, wants three things: no JAR files except the Gradle wrapper, no file over 10 MB, and no changes to workflow files except by its platform team. As the REST API accepts it:

{
  "name": "push: binaries, size, workflows",
  "target": "push",
  "enforcement": "active",
  "bypass_actors": [
    { "actor_id": 4410982, "actor_type": "Team", "bypass_mode": "always" }
  ],
  "rules": [
    {
      "type": "file_path_restriction",
      "parameters": {
        "restricted_file_paths": ["**/*.jar", ".github/workflows/**/*"],
        "ignored_file_paths": ["**/gradle/wrapper/*.jar"]
      }
    },
    {
      "type": "max_file_size",
      "parameters": { "max_file_size": 10 }
    }
  ]
}

The team ID is made up. max_file_size is in megabytes. The Gradle wrapper exception is the documentation's own example, and the workflow path matches the example in GitHub's announcement, which suggested using push rules "to limit changes to your Actions workflows in" .github/workflows/**/*. GitHub changelog, 10 September 2024

The cost#

Push rules block earlier than any other control, which is their value and their cost. A contributor finds out when the push is rejected, before a pull request exists, and has to rewrite local history to remove the file from every commit that contains it. If your contributors are not used to interactive rebase, expect support requests the first few weeks.

The workflow path restriction costs the most. It stops everyone outside the bypass list from pushing a change to .github/workflows/ on any branch, including a feature branch meant for a pull request. Only the platform team can propose workflow changes at all. If you want other people to propose them and the platform team to approve, use code owners on that path instead, as the workflow self-edit guide describes, and keep the push rule for files that must never enter history.

What push rules do not catch#

They match names, extensions, path lengths and sizes. They do not read content, so a credential in an allowed file passes, which is the job of secret scanning push protection. A binary renamed to an allowed extension passes the extension check. Files stored through Git LFS are outside the size limit. Files that entered history before the ruleset was active stay there. Public repositories cannot use push rules.

The decision#

Turn on a push ruleset for private repositories when you can name files that should never exist in history, and start with file size and binary extensions, which rarely block legitimate work. Add path restrictions only for paths where proposing a change, not only merging it, should be limited. Keep the bypass list to one team, and give it allowed exceptions for the files that legitimately break a rule, so the team is not asked to bypass routine work.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading