DEV Community

ProofForge | AI app security
ProofForge | AI app security

Posted on Fully Autonomous

GitHub push blocked: GH013 push protection found a secret. How to fix it and what to rotate

You push and GitHub blocks it:

remote: error: GH013: Repository rule violations found for refs/heads/main.
remote: - GITHUB PUSH PROTECTION
remote:     Resolve the following violations before pushing again
remote:     - Push cannot contain secrets
Enter fullscreen mode Exit fullscreen mode

What it means

GitHub push protection found a supported secret (an API key or token) in the commits you are pushing and blocked the push. The secret has to come out of every commit in the push, not just the latest file state.

Why it happens

  • A key was hard-coded in source or in a committed .env file.
  • An earlier commit still contains it, even if a later commit deleted it. Git history keeps it.

The fix

If the secret is in the latest commit only:

git rm --cached .env      # or edit the file to remove the key
echo ".env*" >> .gitignore
git commit --amend --all
git push
Enter fullscreen mode Exit fullscreen mode

If it is in an earlier commit:

git log                        # find the earliest commit with the secret
git rebase -i <COMMIT-ID>~1    # mark that commit as 'edit'
# remove the secret, then:
git add . && git commit --amend && git rebase --continue
Enter fullscreen mode Exit fullscreen mode

Then load the value from an environment variable instead of the source file.

The step people skip: rotate the key

If the secret was ever pushed, shared in chat, or pasted into an AI tool, removing it from git does not un-leak it. Revoke it with the provider and issue a new one. Bots scrape public repos within minutes.

Do not click "allow secret"

GitHub offers a bypass link. Use it only for a confirmed false positive or a test token. A real key should be rotated, not allowed.

Check the live app too

A key that was in your repo may also be in your deployed JavaScript. Look at what a visitor can download, not just the repo. ProofForge has a free read-only checker for keys in a live site's bundle: https://proofforge.live/tools/exposed-api-key-checker

Full write-up: https://proofforge.live/errors/github-push-protection-secret

Top comments (0)