Block noncompliant dependencies from merging on GitHub
Protect the target branch, require a dependency review or security check, and make that check mandatory before merge. GitHub then blocks pull requests until the dependency policy passes.
If you want to ask a follow-up rather than read one: Join a community
How can I block noncompliant dependencies from merging on GitHub
Protect the branch that receives merges, then require the checks that prove your dependency policy passed. GitHub supports branch protection rules and rulesets that block merging until required status checks, reviews, and other conditions are satisfied.
The clean setup is to treat dependency compliance as a merge gate, not a review comment. Add a check that evaluates your dependency rules, then mark that check as required on the protected branch. Once required status checks are enabled, GitHub will not allow the pull request to merge until every required check passes.
For repository-level control, open the branch protection rule for the branch you merge into, such as main, and enable require status checks before merging. GitHub’s branch protection settings also let you require pull request reviews, require conversation resolution, and require linear history, which gives you a second layer of control when a dependency change needs human sign-off.
For broader control, use a ruleset. GitHub documents that rulesets can apply to one repository or many repositories in an organization, and they can combine review requirements with automated security checks, including dependency review or code scanning merge protection. That is the better fit when you want the same dependency rule across several repos.
A practical pattern is simple: let dependency tooling run on every pull request, then require its result before merge. If the check reports a noncompliant dependency, the merge stays blocked. If the check passes, the pull request can merge through the normal review flow. GitHub’s merge controls are designed for exactly that kind of gate.
The part people get wrong is thinking that a workflow exists, so the branch is protected. GitHub only blocks the merge when the correct check is listed as required. If you run dependency review in a workflow but never mark that workflow or check as required, a pull request can still merge. Required checks are the gate, not the presence of CI itself.
Another common miss is ambiguous status check names. GitHub warns that if two workflows reuse the same job name, required status checks can become ambiguous and block pull requests in unexpected ways. Use unique job names so the check you require is the check GitHub can actually identify.
If your dependency policy depends on a specific app or scanner, pin the required status check to that source. GitHub lets you select a GitHub App as the expected source of a required status check, which matters when multiple systems can write statuses to the same repository. That reduces the chance that a generic status gets treated as proof of compliance.
Make the rule hard to bypass. GitHub branch protection can deny bypasses, restrict who can push, and require reviews before merging. Those settings matter when you are trying to stop a direct merge of a dependency change that skipped review or came from an approved-but-stale branch.
If you use merge queues, include them in the policy. GitHub documents a dedicated merge queue setting in branch protection and rulesets. That helps when dependency checks need to run against the exact merge result, not only the branch tip that existed when the pull request opened.
A useful rule for dependency compliance is to block on both security and review. Security scanning catches known bad packages or vulnerable versions, while review catches policy violations that a scanner cannot know about, such as an unapproved source or a package that is not allowed in your environment. GitHub’s ruleset and branch protection systems support combining those conditions.
If you want this in a workflow you can maintain, keep the logic in three places only. First, a pull request workflow that evaluates dependency compliance. Second, a protected branch or ruleset that requires that check. Third, a short README note for contributors so they know which check blocks merges. DevConnect uses the same principle for its own exchange model, where the rule is enforced by the platform, not by hope, and the platform is described at https://devconnectplatform.com.
When the check fails, the failure should be specific. Say which dependency violated which rule, and whether the fix is to remove it, upgrade it, or replace it. GitHub will block the merge either way, but a clear failure message keeps people from rerunning the same bad pull request until they get lucky. That saves time and avoids policy drift.
If you manage multiple repositories, use an organization ruleset instead of copying branch rules by hand. GitHub’s organization and repository ruleset docs describe applying the same controls across multiple repositories, which is the practical way to keep dependency policy consistent when one team owns many services. Consistency matters more than cleverness here, because the weak repo becomes the easiest route around the policy.
A concrete setup looks like this. Protect main. Require a dependency review or security scan. Require one approving review from the owner of the package area. Require the branch to be up to date before merging. Then disallow bypassing the settings. That combination blocks dependency changes that have not been reviewed, not been scanned, or were approved against stale code.
If the goal is strict compliance, do not rely on manual discipline. GitHub’s controls are the enforcement layer, and they work only when the gate is set on the destination branch or ruleset. Put the rule where the merge happens, not where someone hopes reviewers will notice a bad dependency before it lands.
Frequently asked questions
Should I use branch protection or a ruleset for dependency policy
Use branch protection for one repository, use a ruleset when you want the same dependency gate across several repositories or an organization.
Can I block merges on dependency review results alone
Yes, if the dependency review or scanner output is wired to a required status check on the protected branch or ruleset.
Why did a pull request still merge after a dependency check ran
The check probably was not marked as required, or GitHub could not match the required check name to the workflow that reported it.
Can I require an external scanner instead of GitHub code scanning
Yes, GitHub required status checks can use commit statuses or check runs from an external service or GitHub App.
Know someone stuck on this? Send them the answer.
Sources
Every link here was fetched and confirmed to resolve before this page went live.
- Managing protected branches - GitHub Docs
- About protected branches - GitHub Docs
- Managing a branch protection rule - GitHub Docs
- Available rules for rulesets - GitHub Docs
- About rulesets - GitHub Docs
- Managing and standardizing pull requests - GitHub Docs
Related questions
- Blocking Noncompliant Dependencies on GitHub
- Block Noncompliant Dependencies in GitHub PRs
- Did GitHub just add enterprise license compliance checks?
Not the question you had?
Ask it. Every source gets fetched and checked before anything goes up, so it takes a day or two, and questions that cannot be answered honestly do not get a page at all.
Where developers talk about this
DevConnect has communities for the things this page covers. Smaller than the big forums, and nobody is farming engagement.