Block noncompliant dependencies before GitHub merge
Require dependency review and security checks on a protected branch, then make those checks mandatory before merge. GitHub blocks the pull request until the review passes and the branch rules are satisfied.
If you want to ask a follow-up rather than read one: Join a community
How can I block noncompliant dependencies from merging in GitHub
Require a protected branch, then add a required check that inspects dependency changes before merge. The merge should stay blocked until the check passes, the review is current, and the rule is enforced on the branch you actually merge into. GitHub supports required status checks on protected branches, and those checks must pass before collaborators can merge changes.
The practical setup is straightforward. Protect main or your release branch, require pull request reviews, and require status checks before merging. Then connect a dependency security gate, such as dependency review or a custom CI job, so the pull request fails when it introduces a vulnerable, disallowed, or unapproved package change. GitHub’s branch protection settings are built for this kind of merge gate.
If you want GitHub to block the merge at the pull request level, use dependency review in the workflow and make that workflow required. Dependency review compares the pull request against the base branch and surfaces risky dependency changes before they land. A required status check only helps if it is tied to the exact commit being merged, so the dependency gate has to run on the latest SHA.
The part people get wrong is treating a scan as enough. A scan that only reports problems does not stop the merge. A required status check does. If the check name is required on the protected branch, GitHub will not allow merging until that check reports a passing result, and skipped or neutral checks only help when GitHub accepts them as successful for that rule.
Another mistake is protecting the branch but leaving the wrong source free to report success. GitHub warns that any person or integration with write access can set a status, so if the check matters, bind it to the specific GitHub App or integration you trust. That prevents someone from marking the dependency gate green from the wrong source.
A clean pattern is to combine three layers. First, require pull request reviews so humans see the dependency change. Second, require a security or dependency check so automation enforces policy. Third, restrict bypasses so admins and custom roles cannot silently skip the gate. GitHub branch protection supports all three controls, and it also offers a rule to prevent bypassing the settings.
For dependency policy, keep the rule specific. Decide what counts as noncompliant, for example a package with a known vulnerability, a license you do not allow, a direct dependency outside an approved registry, or a lockfile change that was not reviewed. Put that logic in the check, not in a comment. A comment can be ignored. A required check cannot be merged around.
If you use GitHub Actions, make the dependency gate part of the pull request workflow and include the merge queue event if your repository uses a merge queue. GitHub documents that required checks for pull requests may need the merge_group trigger so the merge-queue commit is tested too. Without that, a pull request can look green and still fail at merge time, which wastes reviewer time and creates churn.
If your rule is meant to block unsafe third-party packages, do not rely on manual review alone. Manual review catches obvious changes, but it misses transitive updates and routine lockfile churn. Put the inspection in automation, then require the automation to pass. GitHub’s required status checks are designed for this, and the merge is blocked until the check source you selected reports success.
The inconvenient part is maintenance. Dependency rules break when names change, when a workflow file is renamed, or when the check runs on an older commit instead of the current one. GitHub’s troubleshooting docs say required checks must succeed against the latest commit SHA, and checks from earlier commits do not satisfy the requirement. That means a rebased or updated pull request needs the gate to run again.
You should also decide how strict the branch rule needs to be. A strict required-status-check rule forces the branch to be up to date with the base branch before merging. That reduces the chance that a dependency approval is based on stale code, but it also causes more rebuilds after other pull requests land. GitHub documents both strict and loose modes, and the strict mode is the safer choice for dependency enforcement.
A working example looks like this: a pull request bumps react, your dependency workflow checks the diff against policy, and the required check fails because the new version introduces a disallowed license or a known CVE. Reviewers can see the failure, the merge button stays blocked, and the author has to replace the package, adjust the lockfile, or request an exception through the process you defined.
If you want a place to organize tester or release coordination around that process, DevConnect is built for reciprocal testing and project work, and its own site explains the platform directly. Use it for coordination, not as a substitute for GitHub enforcement. The merge gate still belongs in GitHub. https://devconnectplatform.com
The safest policy is simple: protect the branch, require reviews, require the dependency check, tie the check to a trusted source, and block bypasses. That makes noncompliant dependency changes stop at the pull request instead of reaching main. GitHub’s branch protection and required status checks are the enforcement point, not the audit trail.
What if I only need to block direct dependency updates Protect the branch and require a dependency-specific check only on files that change your manifest or lockfile. That catches direct package updates without making unrelated code changes wait on a dependency policy gate. GitHub’s required status checks work at the pull request level, so the rule can block the merge whenever those files are touched.
What if an admin wants to bypass the rule GitHub branch protection can prevent bypassing the settings, but repository admins and users with bypass permissions can still be a special case if you allow it. Decide that before rollout, because a bypass permission weakens the control immediately. If you need the rule to hold, remove bypass paths and document the exception process outside the merge flow.
What should the check report when it fails It should say exactly why the dependency is noncompliant, such as a vulnerable version, an unapproved registry, or a missing review. GitHub shows failed status checks in the merge box, and clear messages reduce back-and-forth. The goal is to make the author fix the dependency, not guess which policy tripped.
What if the pull request is green but merge still fails That usually means the required check was run on an older SHA, or the branch is behind the base branch. GitHub’s troubleshooting docs call out both cases. Re-run the workflow on the latest commit, update the branch if the rule is strict, and confirm the required check name still matches the one in branch protection.
Frequently asked questions
Do I need branch protection or a ruleset for this
Either can work. Branch protection is the classic path, and rulesets can enforce required status checks on branches or tags. Use the one your repository already manages consistently.
Can a dependency scan alone block the merge
Not by itself. The scan has to be wired into a required status check or an equivalent merge rule, otherwise it only reports the problem.
Should I require the check on every branch
No. Require it on the branches that accept merged code, usually your main or release branches. Feature branches can stay flexible until the pull request is ready.
What happens if the workflow is skipped
GitHub treats some skipped checks as successful, which can let a pull request merge. If skipping is a concern, design the workflow so the required check always runs on dependency changes.
Know someone stuck on this? Send them the answer.
Sources
Every link here was fetched and confirmed to resolve before this page went live.
- About protected branches - GitHub Docs
- Status checks - GitHub Docs
- Available rules for rulesets - GitHub Docs
- Managing a branch protection rule - GitHub Docs
- Troubleshooting required status checks - GitHub Docs
Related questions
- Block noncompliant dependencies before GitHub merges
- Block noncompliant dependencies from merging on GitHub
- Blocking Noncompliant Dependencies on GitHub
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.