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 --amendfixes 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, yourpush.defaultsetting 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 blocked | What you see | How to fix | Bypass route |
|---|---|---|---|
Command line git push | remote: GH013 output with commits, paths and lines, up to five secrets | Amend or rebase locally, then push | Open 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 upload | Dialog naming the secret location, secret underlined | Edit the file to remove the secret, then commit | Choose 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 protection | Remove the value from the request body | Use 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.
| Situation | Signs | Action | Rotate? |
|---|---|---|---|
| Real credential, only in your local commits | You pasted a key into config or a test while debugging | Remove from every commit (amend or rebase), move it to a secret store or environment variable | Usually not, if it was never pushed, shared or logged anywhere else |
| Real credential that also exists elsewhere | Same value pushed to another remote, a fork, a gist, a ticket or CI output; branch shared with others before the block | Remove from commits and rotate with the issuing provider | Yes |
| Not a secret | Documented example value, revoked sample token, a string that only looks like a key | Bypass with "It's a false positive", or ask for the path to be excluded if it recurs | No |
| Deliberate test credential | A credential that only works against a local emulator or sandbox with no real access | Bypass with "It's used in tests", or replace with an obviously fake value | Confirm 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
- 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).
- Run
git commit --amend --allso the original commit is rewritten rather than followed by a new one. - Run
git push. If the block returns, the secret is in an earlier commit too.
The secret is in earlier commits
- From the block message, list every commit that contains the secret, and use
git logto find the earliest one. - Run
git rebase -i <EARLIEST-COMMIT>~1. - In the editor, change
picktoediton the earliest commit's line (and on any later listed commit that reintroduces the secret), then save and close. - When the rebase stops, remove the secret, run
git add .andgit commit --amend. - 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. - 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 --softto the branch point, remove the secret, commit once) than to edit a dozen commits. Check the result withgit log -pbefore 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.
| Reason | Meaning | Resulting alert | Use it when |
|---|---|---|---|
| It's used in tests | The secret is used only in tests and poses no threat | Closed alert | A deliberate fixture that grants no real access |
| It's a false positive | The detected string is not a secret | Closed alert | Example values, documentation placeholders, already revoked samples |
| I'll fix it later | The secret is real and will be fixed later | Open alert; the commit author and repository administrators are notified | Rarely: 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.
- Open the URL from the block message (command line) or choose "Start request" (web UI), as the user who pushed.
- 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").
- Select "Submit request" and wait for the email decision. Requests expire after 7 days.
- 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
.envand local config files to.gitignorefrom 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.defaultdeliberately so a push does not carry stale branches that contain old secrets.
Small team or large organisation
| Concern | Small team | Large organisation |
|---|---|---|
| Who can bypass | Default model (anyone with write access, with a reason) is workable if the lead reviews bypass alerts weekly | Delegated bypass, with a named reviewer team and a target response time well inside the 7-day expiry |
| Recurring false positives | Bypass once with "false positive", fix the fixture | Reviewed paths-ignore list with owner and reason per entry |
| Rotation | Developer rotates with provider, records it in the pull request | Credential owner team rotates; developer raises a ticket linked to the alert |
| Automation | Avoid bots writing secrets into code | Exempt 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-ignorepattern 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
| Framework | Reference | How this runbook supports it |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-5(7) No Embedded Unencrypted Static Authenticators | Removing the credential from code and moving it to a store |
| NIST SP 800-53 Rev 5 | IA-5 Authenticator Management; SA-11 Developer Testing and Evaluation | Rotation when exposure is possible; push-time checks as part of developer testing |
| NIST CSF 2.0 | PR.PS-06; PR.AA-01 | Secure development practice; managed credentials for services |
| ISO/IEC 27001:2022 Annex A | A.5.17 Authentication information; A.8.4 Access to source code; A.8.28 Secure coding | Credentials kept out of repositories and handled through a defined process |
| MITRE ATT&CK | T1552.001 Credentials In Files; T1213.003 Code Repositories | The 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
- GitHub Docs: Working with push protection from the command line
- GitHub Docs: Working with push protection in the GitHub UI
- GitHub Docs: Command line push protection
- GitHub Docs: About push protection
- GitHub Docs: About delegated bypass for push protection
- GitHub Docs: Excluding folders and files from secret scanning
- GitHub Docs: Removing sensitive data from a repository
- Git: git-rebase documentation
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