Join our Newsletter — 33% off our NHI Course
Home› Guides› What to do when git push is blocked…
Guide Software & AI Supply Chain

What to do when git push is blocked by secret scanning push protection: remove, bypass or rotate the right way

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 15 November 2026 15 min read
On this page

A push rejected with "GH013: Repository rule violations found" and "Push cannot contain secrets" means GitHub found a credential in your new commits and refused them, and the commonest wrong fix is to delete the line in a new commit and push again, which fails because the secret is still in the earlier commit. This guide is the developer-side runbook for that moment: how to read the block message, how to take the secret out of every local commit that contains it, when a bypass is legitimate and which reason to pick, how delegated bypass requests work, and when the credential still needs rotating even though the push never landed. It is for developers who hit the block and for the team leads and security engineers who field their questions. Turning push protection on and choosing the bypass model are covered in How to enable GitHub secret scanning push protection; how the control works in general is in the Push Protection Guide.

This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.

Key takeaways

  • The secret must leave every commit in the push. GitHub's documentation says you must remove the secret from all of the commits it appears in; a follow-up commit that deletes it does not clear the block.
  • Amend for the latest commit, rebase for older ones. git commit --amend fixes the tip; an interactive rebase from the earliest affected commit fixes the rest, and nothing needs force-pushing because the commits never reached the server.
  • A bypass is a statement, not a workaround. "It's used in tests" and "It's a false positive" create closed alerts; "I'll fix it later" creates an open alert that owners are notified about. Pick the reason that is true.
  • No bypass button means delegated bypass is on. Submit a request with a real justification; requests expire after 7 days and an approval covers future pushes of the same secret.
  • Blocked does not always mean safe. The push was stopped, but a secret that is also in another remote, a pasted log, a CI cache or a shared branch still needs rotating with its provider.

Reading the block message

On the command line the rejection arrives as remote: lines. A typical rejection looks like this: error: GH013: Repository rule violations found for refs/heads/<branch>, then Push cannot contain secrets, then a block per secret type with a locations: list giving the commit hash and path: with file and line for each occurrence, a URL to allow the secret, and finally [remote rejected] ... (push declined due to repository rule violations). Read three things before touching anything.

  • Secret type: the provider pattern that matched (for example a personal access token or a cloud access key). This tells you who issued the credential and who can rotate it.
  • Every commit listed: if the same secret appears in several commits, each one is listed, and the earliest is where your rebase must start.
  • The ref: the branch named after refs/heads/. If it is not the branch you meant to push, your push.default setting may be pushing more refs than the current branch, which GitHub notes can cause unexpected blocks.

GitHub displays up to five detected secrets at a time on the command line, so after fixing those, push again and expect a second round if the branch carried more. In the web editor the dialog shows one secret at a time and underlines it in the file. A secret that already has an alert in the repository is not blocked again, which is why a colleague may have pushed the same value without trouble.

Where you were blockedWhat you seeHow to fixBypass route
Command line git pushremote: GH013 output with commits, paths and lines, up to five secretsAmend or rebase locally, then pushOpen the URL as the same user who pushed (another user gets a 404), choose a reason, retry within three hours
Web UI commit or file uploadDialog naming the secret location, secret underlinedEdit the file to remove the secret, then commitChoose a reason and "Allow secret", or "Start request" for delegated bypass
REST API (for example creating file contents or a blob)Request rejected by push protectionRemove the value from the request bodyUse the bypass route GitHub documents for the REST API, or the web UI request flow

Triage before you rewrite anything

Spend one minute deciding which of four situations you are in. The answer decides whether you rewrite, bypass, request or escalate.

SituationSignsActionRotate?
Real credential, only in your local commitsYou pasted a key into config or a test while debuggingRemove from every commit (amend or rebase), move it to a secret store or environment variableUsually not, if it was never pushed, shared or logged anywhere else
Real credential that also exists elsewhereSame value pushed to another remote, a fork, a gist, a ticket or CI output; branch shared with others before the blockRemove from commits and rotate with the issuing providerYes
Not a secretDocumented example value, revoked sample token, a string that only looks like a keyBypass with "It's a false positive", or ask for the path to be excluded if it recursNo
Deliberate test credentialA credential that only works against a local emulator or sandbox with no real accessBypass with "It's used in tests", or replace with an obviously fake valueConfirm it truly grants nothing; if unsure, treat as real

If you cannot tell whether a value is live, treat it as real. The Developer Secret Scanning Triage guide covers validity checks across tools.

Step-by-step: remove the secret from local commits

These steps follow GitHub's documented procedure. Because the push was rejected, the remote does not hold these commits, so rewriting them is local only. Before starting, make a safety branch with git branch backup-before-secret-fix so you can return if the rebase goes wrong, and delete that branch once you have pushed successfully, because it still contains the secret.

The secret is only in the latest commit

  1. Remove the secret from the file and replace it with a reference to where it should live (an environment variable, a secrets manager lookup, a CI secret).
  2. Run git commit --amend --all so the original commit is rewritten rather than followed by a new one.
  3. Run git push. If the block returns, the secret is in an earlier commit too.

The secret is in earlier commits

  1. From the block message, list every commit that contains the secret, and use git log to find the earliest one.
  2. Run git rebase -i <EARLIEST-COMMIT>~1.
  3. In the editor, change pick to edit on the earliest commit's line (and on any later listed commit that reintroduces the secret), then save and close.
  4. When the rebase stops, remove the secret, run git add . and git commit --amend.
  5. Run git rebase --continue. If a later commit conflicts because it edited the same line, resolve the conflict without bringing the secret back, then continue.
  6. Run git push.

If the rebase goes wrong, git rebase --abort resets the branch to where it was when the rebase started, and the previous tip stays reachable in the reflog as @{1}. Git's own documentation warns that rewriting a branch other people have based work on forces everyone downstream to repair their history, so if teammates already fetched these commits from somewhere else, coordinate before rewriting.

Large or messy branches

  • Many commits touch the file: it can be simpler to squash the feature branch into one clean commit (git reset --soft to the branch point, remove the secret, commit once) than to edit a dozen commits. Check the result with git log -p before pushing.
  • The secret is in a merge you pulled in: the commit is someone else's. Do not bypass it on their behalf; tell the owner, and if the value reached another remote, start rotation.
  • The secret is in a large generated or vendored file: remove the file from the commits and add it to .gitignore; regenerate it at build time.
  • The value was already pushed and accepted elsewhere: rewriting local commits does not clean other remotes. Use How to Remove Secrets From Git History, and rotate first.

When a bypass is the right answer

When the repository has secret scanning enabled, a bypass requires one of three reasons, and each has a different consequence. GitHub's documentation describes them as follows.

ReasonMeaningResulting alertUse it when
It's used in testsThe secret is used only in tests and poses no threatClosed alertA deliberate fixture that grants no real access
It's a false positiveThe detected string is not a secretClosed alertExample values, documentation placeholders, already revoked samples
I'll fix it laterThe secret is real and will be fixed laterOpen alert; the commit author and repository administrators are notifiedRarely: an emergency fix where you have already started rotation and have an owner and date

After choosing a reason and selecting "Allow me to push this secret", retry the push within three hours; after that the process starts again. Every bypass in a repository with push protection enabled creates an alert, adds an audit log event and emails owners, security managers and repository administrators who watch the repository. Choosing "false positive" for a real key does not hide it: the alert still exists, the audit trail records who chose that reason, and the security team will see it.

Two practical rules keep bypasses honest. First, never bypass to get a release out with a production credential in it: the secret is then in the remote history and in every clone, and fixing it later means rotation plus a history rewrite. Second, if the same false positive keeps blocking a team, ask an administrator to exclude the path with paths-ignore in .github/secret_scanning.yml rather than bypassing each time. Exclusions apply to push protection as well as scanning, only the first 1,000 entries are used, and GitHub recommends telling the security team which paths are excluded and why, so keep the list short and reviewed.

When there is no bypass option: delegated bypass

If the block offers no reasons, an administrator has turned on delegated bypass, which is available for organisation-owned repositories with GitHub Secret Protection. Only listed roles, teams and individuals can bypass directly; everyone else goes through review.

  1. Open the URL from the block message (command line) or choose "Start request" (web UI), as the user who pushed.
  2. Under "Or request bypass privileges", write a comment a reviewer can act on: what the value is, why it is not a live secret or why it must be pushed, and what you have already done (for example "test key for local emulator, grants no access" or "sample token from vendor documentation").
  3. Select "Submit request" and wait for the email decision. Requests expire after 7 days.
  4. If approved, push again; the approval covers the commits containing that secret and future commits with the same secret. If denied, remove the secret from every commit as above.

A request that says only "please allow" slows everyone down and is likely to be denied. Reviewers are usually organisation owners, security managers or holders of a custom role with permission to review and manage secret scanning bypass requests.

Rotate when the secret may have escaped

Push protection stops the push, not the credential's other journeys. GitHub states that real secrets that have been exposed must be revoked, and suggests rotating before revoking to avoid an outage. Rotate the credential with its issuer if any of these are true:

  • Another remote: the same commits went to a mirror, fork, personal repository or another Git host.
  • Shared before the block: a teammate pulled your branch from a shared machine or another remote.
  • Logs and tickets: the value appears in CI logs, terminal recordings, chat, an issue or an AI assistant prompt.
  • Bypassed: anyone chose "I'll fix it later", or chose "false positive" or "used in tests" for a value that turns out to be live.
  • Unknown: you cannot say where the value has been.

The provider-side steps are in the Leaked Credential Response Playbook, and closing the resulting GitHub alert correctly is in How to respond to a GitHub secret scanning alert.

Stop it happening again

  • Keep secrets out of the working tree: load credentials from environment variables or a secrets manager, and add .env and local config files to .gitignore from the start.
  • Catch it before the commit: a pre-commit secret scanner stops the value entering local history at all, so no rebase is ever needed. See the Git Hooks and Pre-commit Security Guide.
  • Use fake values in tests: a value that cannot be mistaken for a live key avoids both blocks and bypass debates.
  • Prefer short-lived credentials: workload identity federation and short-lived tokens leave nothing durable to paste. See the Secrets Management Guide.
  • Check your push scope: set push.default deliberately so a push does not carry stale branches that contain old secrets.

Small team or large organisation

ConcernSmall teamLarge organisation
Who can bypassDefault model (anyone with write access, with a reason) is workable if the lead reviews bypass alerts weeklyDelegated bypass, with a named reviewer team and a target response time well inside the 7-day expiry
Recurring false positivesBypass once with "false positive", fix the fixtureReviewed paths-ignore list with owner and reason per entry
RotationDeveloper rotates with provider, records it in the pull requestCredential owner team rotates; developer raises a ticket linked to the alert
AutomationAvoid bots writing secrets into codeExempt only trusted automation (GitHub suggests migration bots or service accounts) and review that exemption list

Detection and measurement

For the security team, the blocked push is the good outcome; the signals worth watching are what happens afterwards. Bypass events are written to the audit log and create alerts, so route both to the people who own rotation.

  • Bypass rate: bypasses as a share of blocks per repository; a rising rate means developers treat the block as friction rather than a stop.
  • "I'll fix it later" age: open alerts created by that reason, and how long they stay open. Target closure within days, with rotation evidence.
  • False positive bypasses later confirmed live: should be zero; each one is a coaching conversation and a rotation.
  • Bypass request turnaround: median time from request to decision; anything near 7 days means requests are expiring unanswered.
  • Repeat offenders by path: the same files blocked again and again point to a fixture or config pattern that needs fixing, not more bypasses.

Common failure patterns

  • Deleting the line in a new commit. The secret stays in the earlier commit, the push is blocked again, and the developer then reaches for a bypass instead of a rebase.
  • Bypassing a real key as a false positive. It gets the push through but creates a closed alert that hides a live credential in remote history, and the audit log shows who chose the reason.
  • Forgetting the backup branch. A safety branch made before the rebase still holds the secret; pushing it later, or pushing all branches, brings the secret straight back.
  • Assuming blocked means contained. The value was also in a CI log or another remote, and nobody rotated it because "the push failed".
  • Excluding whole directories to stop the noise. A broad paths-ignore pattern such as a top-level config folder stops push protection for real secrets in that path too.
  • Vague bypass requests. Requests without context sit until they expire after 7 days, and developers learn to work around the process.

Framework mapping

FrameworkReferenceHow this runbook supports it
NIST SP 800-53 Rev 5IA-5(7) No Embedded Unencrypted Static AuthenticatorsRemoving the credential from code and moving it to a store
NIST SP 800-53 Rev 5IA-5 Authenticator Management; SA-11 Developer Testing and EvaluationRotation when exposure is possible; push-time checks as part of developer testing
NIST CSF 2.0PR.PS-06; PR.AA-01Secure development practice; managed credentials for services
ISO/IEC 27001:2022 Annex AA.5.17 Authentication information; A.8.4 Access to source code; A.8.28 Secure codingCredentials kept out of repositories and handled through a defined process
MITRE ATT&CKT1552.001 Credentials In Files; T1213.003 Code RepositoriesThe techniques that make committed secrets valuable to attackers

Practitioner checklist

  • Read the whole block message: secret type, every commit listed and the ref being pushed.
  • Decide first whether the value is real, shared elsewhere, a false positive or a test value.
  • Create a backup branch, then amend or interactively rebase from the earliest affected commit.
  • Replace the secret with an environment variable or secrets manager reference, never another literal.
  • Push again and repeat if more secrets appear (up to five are shown at a time).
  • Bypass only with the reason that is true, and retry within three hours.
  • Write delegated bypass requests a reviewer can approve without asking questions.
  • Rotate with the provider if the value may exist anywhere outside your local commits.
  • Delete the backup branch after a clean push.
  • Add a pre-commit scanner so the next secret never reaches a commit.

Standards and references

Related NHI Mgmt Group resources: Push Protection Guide · How to enable GitHub secret scanning push protection · How to Remove Secrets From Git History · Git Secret Scanning Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 15 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.