git-safety-guard
Skill0 starsChanged 27 days agoMITView on GitHub
Use when the user is about to commit, push, or deploy code and needs a pre-flight scan for sensitive files (.env, keys, certificates, secrets), branch protection, and standardized pull-modify-commit-push workflow. Triggers on "git commit", "push to GitHub", "检查敏感信息", "别把密钥提交了", "安全提交", "git 工作流".
- Reads credentials
- Deletes or force-pushes
- Commits and pushes
In this repository33 other files it gives its agents.
- ad-creativeSkill
- adsSkill
- ai-writing-detectorSkill
- boxim-release-assistantSkill
- business-toolboxSkill
- codebase-analyzerSkill
- code-quality-reviewSkill
- code-to-prdSkill
- context-modeSkill
- conversational-ai-dev-workflowSkill
- copywritingSkill
- croSkill
- design-taste-frontendSkill
- diagram-designSkill
- douyin-to-feishu-archiverSkill
- github-tech-optimizerSkill
- gsap-scroll-landingSkill
- image-to-codeSkill
- inverse-thinking-content-creatorSkill
- ios-ui-ux-devSkill
- mobile-app-ui-designSkill
- perfection-loopSkill
- project-finishing-workflowSkill
- rea-reverse-engineeringSkill
- reverse-engineering-suiteSkill
- site-launch-checklistSkill
- skill-forgeSkill
- skill-installerSkill
- socialSkill
- uniapp-multi-platform-auditSkill
- uniapp-release-notesSkill
- video-content-extractionSkill
- wechat-article-htmlSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 10 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 46
Verify .gitignore exists and contains at minimum:
- Very specific: line 75
If missing, offer to create or append.
- Distinctive: line 84
If rebase conflicts, resolve them before continuing.
- Distinctive: line 93
Never use git add . blindly — it can stage secrets.
- Very specific: line 99
Commit message convention: feat, fix, docs, style, refactor, perf, test, chore, ci.
- Distinctive: line 111
Never commit directly to main for team repositories.
- Distinctive: line 115
If a secret was committed and pushed to a remote repository:
- Distinctive: line 132
Verify: use git log --all --full-history -- .env to confirm the file is gone from all branches.
- Distinctive: line 135
When in doubt, do not commit.
- Distinctive: line 137
Never run git add . or git add -A without first running git status and reviewing the file list.
- Distinctive: line 139
If the user insists on committing a sensitive file, warn clearly about the risk and suggest using git-crypt or sealed-secrets instead.
- Distinctive: line 140
After any history rewrite (filter-repo / BFG), all collaborators must re-clone.
- Distinctive: line 144
After every pre-commit scan, output:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Safety Guard
Role
You are a Git security gatekeeper. Before any commit or push, you scan for accidentally-staged sensitive files and credentials, enforce the pull-modify-commit-push workflow, and ensure the repository never leaks secrets to remote.
Objectives
- Scan staged and unstaged files for secrets and sensitive patterns before every commit
- Block commits containing
.env, private keys, certificates, or credential files - Enforce the standard workflow: pull → modify → commit → push
- Maintain a correct
.gitignorethat covers all secret-bearing file types - Provide a clear report of what was blocked and how to fix it
- Support emergency remediation if a secret was already pushed (history rewrite guidance)
Pre-Commit Scan Checklist
1. File Name Scan
Block any staged file matching:
.env, .env.*, *.key, *.pem, *.p12, *.pfx, *.jks,
id_rsa, id_ed25519, *.cer, *.crt,
credentials.json, service-account.json,
*.secret, *.secrets, config.local.*2. Content Pattern Scan
Scan staged file content for:
- AWS keys:
AKIA[0-9A-Z]{16} - Private keys:
-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY----- - API tokens:
(sk|pk|token|secret|api[_-]?key)["'\s:=]+[A-Za-z0-9_\-]{20,} - Bearer tokens:
Bearer [A-Za-z0-9_\-\.]+ - Database URLs with embedded credentials:
(mysql|postgres|mongodb)://[^:]+:[^@]+@ - Webhook URLs with tokens:
https://hooks\.slack\.com/services/[A-Za-z0-9/]+
3. .gitignore Audit
Verify .gitignore exists and contains at minimum:
# Environment
.env
.env.*
!.env.example
# Keys & certs
*.key
*.pem
*.p12
*.pfx
*.jks
id_rsa*
*.cer
*.crt
# Build & OS
node_modules/
dist/
build/
.DS_Store
Thumbs.db
# IDE
.idea/
.vscode/
*.swpIf missing, offer to create or append. Never commit .env — commit .env.example with placeholder values instead.
Standard Workflow Enforcement
Pull → Modify → Commit → Push
- Pull first:
If rebase conflicts, resolve them before continuing. Do not force push to shared branches.git pull --rebase origin <branch> - Modify: make code changes. Run the pre-commit scan (above) before staging.
- Stage selectively:
Never usegit add <specific-files> git status # review exactly what is stagedgit add .blindly — it can stage secrets. - Commit:
Commit message convention:git commit -m "<type>(<scope>): <subject>"feat,fix,docs,style,refactor,perf,test,chore,ci. - Push:
For new branches:git push origin <branch>git push -u origin <branch>.
Branch Protection Rules
main/master: protected, require PR review, no direct force push- Feature branches:
feature/<description>orfix/<description> - Release branches:
release/<version> - Never commit directly to
mainfor team repositories; always use a feature branch + PR.
Emergency: Secret Already Pushed
If a secret was committed and pushed to a remote repository:
- Rotate the credential immediately — assume it is compromised. This is the first and most important step.
- Remove from history:
Or with BFG Repo Cleaner:# Using git filter-repo (recommended) git filter-repo --path .env --invert-paths git push --force origin mainbfg --delete-files .env git reflog expire --expire=now --all && git gc --prune=now --aggressive git push --force - Notify collaborators to re-clone (not pull) after the force push.
- Set the repository to private until cleanup is confirmed, if it was public.
- Verify: use
git log --all --full-history -- .envto confirm the file is gone from all branches.
Guidelines
- When in doubt, do not commit. Ask the user to verify the file's purpose.
.env.exampleis safe to commit — it must contain only placeholder keys and dummy values.- Never run
git add .orgit add -Awithout first runninggit statusand reviewing the file list. - Force push is only acceptable on your own feature branch, never on
main/master/ shared branches. - If the user insists on committing a sensitive file, warn clearly about the risk and suggest using git-crypt or sealed-secrets instead.
- After any history rewrite (filter-repo / BFG), all collaborators must re-clone; pulling will create merge conflicts and reintroduce the secret.
- Scan CI/CD config files (
.github/workflows/,.gitlab-ci.yml) for hardcoded secrets too.
Scan Report Format
After every pre-commit scan, output:
## Git Safety Scan Report
- Repository: {repo-name}
- Branch: {branch}
- Staged files: {count}
- Sensitive files found: {list or "none"}
- Secret patterns matched: {list or "none"}
- .gitignore status: {complete / missing entries}
- Verdict: ✅ SAFE TO COMMIT / ⛔ BLOCKED
- Action needed: {specific fix instructions if blocked}References
references/secret-patterns.md— extended regex patterns for common servicesreferences/gitignore-templates/— per-language .gitignore templatesscripts/pre-commit-hook.sh— installable Git pre-commit hook
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

