Skip to main content
Git & Version Control · Developer Error Resolution Lab

Fix GitHub Error 'remote: error: GH013: Repository rule violations found — Push cannot contain secrets'

Scan and scrub accidentally committed API keys or tokens from your Git commit history using Castov Secret Scanner and `git reset`.

Triggered Error Message:

remote: error: GH013: Repository rule violations found for refs/heads/main. - Push cannot contain secrets

Customize Solution for Your Environment
# 1. Scan all files locally (100% offline) to locate every leaked token:
npx castov scan .

# 2. Undo the last 1 local commit(s) while keeping your working tree changes:
git reset --soft HEAD~1

# 3. Rotate the compromised key or generate a new cryptographic secret:
npx castov secret 32

Root Cause & Mechanism Analysis

Why does this error occur?

GitHub Push Protection detected a live credential pattern (such as an AWS key, Stripe secret, or OpenAI token) inside one of the commits being pushed—even if you deleted the secret in a later commit.

Frequently Asked Questions

How do I prevent GH013 before committing?
Run `npx castov scan .` in a pre-commit hook or let your AI coding agent call `castov_scan_secrets` via the Castov MCP server before staging files.
DEVSECOPS & CI/CD PARTNER2 Slots Open

Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?

Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.

Browse All 54 Guides