GH013: Push cannot contain secrets
GitHub found an API key or other secret in the commits you tried to push and blocked the whole push so the secret wouldn’t land in the repository.
Also appears as
- remote: error GH009: Secrets detected! This push failed.
Prompt to fix it
git push was blocked by GitHub push protection: "GH013: Repository rule violations found" and "Push cannot contain secrets". Find every secret listed in the error and move it into environment variables, add .env files to .gitignore, and stop tracking them with git rm --cached. Then rewrite only my unpushed commits so none of them contains the secret, and push again. Don’t use the allow-secret link, and don’t force push over commits that are already on GitHub. Tell me which keys I need to rotate.
Paste into Layerwise or any AI coding tool.
What it means
GitHub push protection scans every push for known secret formats: API keys from OpenAI, Stripe, AWS, Supabase, and many more. When it finds one, it rejects the entire push and lists each secret by type, commit, and file line. It checks every commit in the push, so deleting the key in a new commit doesn’t help while an older commit still contains it.
Most of the time the file is .env. AI tools often create it with real keys, and if .gitignore doesn’t list it, git add . commits it. Sometimes the key sits in source code instead, pasted into a config file or a fetch call.
The block kept the key off GitHub, but rotate it anyway: the commit may also exist in other clones, backups, or remotes, and a new key takes a minute to make. GitHub’s link to allow the secret puts it into the repository’s history, where anyone with access can read it, so use it only for test or fake values.
Common causes
.envor.env.localisn’t listed in.gitignore, sogit add .committed real keys.- A key was pasted straight into source code, such as an OpenAI or Stripe secret key in a config file.
- The key was removed in a later commit, but an earlier commit in the same push still has it.
- A sample file like
.env.exampleor a test fixture contains a real key.
How to fix it
- Read the locations list. It names each commit and
file:linethat holds a secret. - Rotate the key: create a new one in the provider’s dashboard, update it wherever the app runs, and revoke the old one.
- Move secrets into environment variables. Add
.env*to.gitignore, with!.env.exampleif you share a template, then rungit rm --cached .env. - If only your latest commit has the secret, remove it and run
git commit --amend --no-edit. If older unpushed commits have it, rungit reset --soft origin/mainto undo those commits while keeping every change staged, then commit again. - Push again. Because none of the new commits contain the secret, a normal
git pushworks.
Example fix
# Keep .env files out of git from now on.
printf '.env*\n!.env.example\n' >> .gitignore
git rm --cached .env
# Undo the unpushed commits but keep every change staged.
git reset --soft origin/main
git add .gitignore
git commit -m "Add app without secrets"
git pushRelated errors
All errorsIt looks like you're running in a browser-like environment
The AI SDK refused to run in the browser, because your secret API key would be visible to anyone who opens the page.
Failed to push some refs
GitHub has commits your copy doesn’t, so git refused to overwrite them until you bring those changes in.
Incorrect API key provided
The AI API rejected the key your code sent: it has a typo, was revoked, or isn’t the key you think the app is using.
fatal: not a git repository
Git searched this folder and every folder above it and found no repository, so the command has nothing to work on.
Build with an agent that checks its work
The Layerwise agent clicks through the live preview and reads the console, so it catches errors before you do.