agentleFS
AthenDrakomin-hubAthenDrakomin-hub/agent-skills/skills/git-safety-guard/SKILL.md

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

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
  1. Very specific:

    Verify .gitignore exists and contains at minimum:

    line 46
  2. Very specific:

    If missing, offer to create or append.

    line 75
  3. Distinctive:

    If rebase conflicts, resolve them before continuing.

    line 84
  4. Distinctive:

    Never use git add . blindly — it can stage secrets.

    line 93
  5. Very specific:

    Commit message convention: feat, fix, docs, style, refactor, perf, test, chore, ci.

    line 99
  6. Distinctive:

    Never commit directly to main for team repositories.

    line 111
  7. Distinctive:

    If a secret was committed and pushed to a remote repository:

    line 115
  8. Distinctive:

    Verify: use git log --all --full-history -- .env to confirm the file is gone from all branches.

    line 132
  9. Distinctive:

    When in doubt, do not commit.

    line 135
  10. Distinctive:

    Never run git add . or git add -A without first running git status and reviewing the file list.

    line 137
  11. Distinctive:

    If the user insists on committing a sensitive file, warn clearly about the risk and suggest using git-crypt or sealed-secrets instead.

    line 139
  12. Distinctive:

    After any history rewrite (filter-repo / BFG), all collaborators must re-clone.

    line 140
  13. Distinctive:

    After every pre-commit scan, output:

    line 144

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 .gitignore that 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/
*.swp

If missing, offer to create or append. Never commit .env — commit .env.example with placeholder values instead.

Standard Workflow Enforcement

Pull → Modify → Commit → Push

  1. Pull first:
    git pull --rebase origin <branch>
    If rebase conflicts, resolve them before continuing. Do not force push to shared branches.
  2. Modify: make code changes. Run the pre-commit scan (above) before staging.
  3. Stage selectively:
    git add <specific-files>
    git status   # review exactly what is staged
    Never use git add . blindly — it can stage secrets.
  4. Commit:
    git commit -m "<type>(<scope>): <subject>"
    Commit message convention: feat, fix, docs, style, refactor, perf, test, chore, ci.
  5. Push:
    git push origin <branch>
    For new branches: git push -u origin <branch>.

Branch Protection Rules

  • main / master: protected, require PR review, no direct force push
  • Feature branches: feature/<description> or fix/<description>
  • Release branches: release/<version>
  • Never commit directly to main for team repositories; always use a feature branch + PR.

Emergency: Secret Already Pushed

If a secret was committed and pushed to a remote repository:

  1. Rotate the credential immediately — assume it is compromised. This is the first and most important step.
  2. Remove from history:
    # Using git filter-repo (recommended)
    git filter-repo --path .env --invert-paths
    git push --force origin main
    Or with BFG Repo Cleaner:
    bfg --delete-files .env
    git reflog expire --expire=now --all && git gc --prune=now --aggressive
    git push --force
  3. Notify collaborators to re-clone (not pull) after the force push.
  4. Set the repository to private until cleanup is confirmed, if it was public.
  5. Verify: use git log --all --full-history -- .env to confirm the file is gone from all branches.

Guidelines

  1. When in doubt, do not commit. Ask the user to verify the file's purpose.
  2. .env.example is safe to commit — it must contain only placeholder keys and dummy values.
  3. Never run git add . or git add -A without first running git status and reviewing the file list.
  4. Force push is only acceptable on your own feature branch, never on main / master / shared branches.
  5. If the user insists on committing a sensitive file, warn clearly about the risk and suggest using git-crypt or sealed-secrets instead.
  6. After any history rewrite (filter-repo / BFG), all collaborators must re-clone; pulling will create merge conflicts and reintroduce the secret.
  7. 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 services
  • references/gitignore-templates/ — per-language .gitignore templates
  • scripts/pre-commit-hook.sh — installable Git pre-commit hook

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.