git-mastery
Advanced git operations covering branches, conventional commits, worktrees, and rebasing. Use for any git operation beyond basic add/commit/push, for branch management, rebasing, and conflict resolution, or when setting up commit conventions for a project.
- License 许可
- MIT
- 所属仓库
- muratovv/ai-hats
- 最近更新
- 2026-11-05
- Stars
- ★ 3
- Forks
- 1
01 前言 Front Matter
- name
- git-mastery
- ai_hats
- { "type": "skill", "schema_version": 1 }
- license
- MIT
- description
- Advanced git operations covering branches, conventional commits, worktrees, and rebasing. Use for any git operation beyond basic add/commit/push, for branch management, rebasing, and conflict resolution, or when setting up commit conventions for a project.
02 资源文件 8
- 其他git_hooks/.privacy-allowlist546 B
- 脚本git_hooks/post-commit-bypass-stamp.sh672 B
- 脚本git_hooks/pre-commit-docs-index.sh3.1 KB
- 脚本git_hooks/pre-commit-no-raw-destructive.sh6.0 KB
- 脚本git_hooks/pre-commit-privacy.sh9.0 KB
- 脚本git_hooks/pre-commit-smoke.sh4.5 KB
- 脚本git_hooks/pre-push-bypass-report.sh3.7 KB
- 脚本git_hooks/pre-push-shared-state.sh3.6 KB
03 SKILL.md 正文
Git Mastery
When to Use
Basic add/commit/push needs no skill — reach here only for harder operations: rebases, conflict resolution, branch strategy, conventional-commit setup, cherry-pick/backport. The git-worktree lifecycle (create/merge/discard a task worktree) is owned by worktree-isolation — use that for isolation, this for history and branch manipulation.
Capabilities
- Create feature branches with naming conventions
- Stage and commit with conventional commit format
- Resolve merge conflicts
- Manage worktrees for parallel development
- Interactive rebase for clean history
- Cherry-pick and backport changes
Conventions
- Branch naming:
type/description(e.g.,feat/add-auth,fix/login-bug) - Conventional commits:
type(scope): description - Types: feat, fix, refactor, docs, test, chore, ci
- Commit messages explain WHY, not WHAT
- Commit frequently with atomic changes
- Check status before operations
- Never force push without explicit approval
Pre-Commit Checklist
Before every git add / git commit:
- Run
git statusandgit diff --statto review what will be committed. - For each file verify:
- Project code? (not agent config like ai-hats.yaml, .agent/)
- Meaningful content? (not empty placeholders)
- Belongs in the repo? (not .env, credentials, temp files)
"Don't commit" failure modes (agent configs, empty placeholders, .gitignore
material) are listed under Anti-Patterns.
Pre-Commit Privacy Review
The pre-commit-privacy.sh hook (installed into .githooks/pre-commit.d/
whenever a role composing git-mastery is applied) scans staged additions and
blocks the commit on:
| Pattern | Examples |
|---|---|
| Absolute home paths | /Users/foo/..., /home/bar/... |
| API key prefixes | sk-..., ghp_..., AKIA..., xox[bp]-..., AIza..., glpat-... |
| Bearer tokens | Authorization: Bearer ... |
| Env-style secrets | *_KEY=, *_TOKEN=, *_SECRET=, *_PASSWORD=, *_API= |
| Email addresses | any RFC-shaped address |
| Private keys | -----BEGIN ... PRIVATE KEY----- (PEM/OpenSSH headers) |
| DB URIs with creds | postgres://user:pass@…, mysql://…, mongodb://…, redis://… |
| Cloud / SaaS tokens | GitHub gho_/ghs_/ghu_/ghr_/github_pat_, AWS secret keys, Slack webhooks, Stripe sk_live_, SendGrid, npm tokens, JWTs |
| Claude session content | JSONL markers — "sessionId"/"requestId", "cwd": "/…", "parentUuid"/"toolUseResult" |
Soft warning (printed, non-blocking): new file in tests/fixtures/ larger than 5 KB.
When the hook fires
- Show the user the full hook report first.
- Don't blindly override — ask whether the hit is a true positive.
- True leak → fix the file, re-stage, retry.
- False positive on a single line → append the inline allow-marker; only that line is skipped:
<the flagged line> # ai-hats: allow-secret - False positive across a whole file that will recur → add a glob to
.privacy-allowlist(project root or.githooks/) and document the reason in the same commit. - Last resort — whole commit →
AI_HATS_PRIVACY_ACK=1, after showing the user what was flagged. The supervisor exports it in the shell that runs the commit; a prefix you write yourself is refused — see safety-guard.
Pre-Commit Smoke Gate
The pre-commit-smoke.sh hook runs pytest -m smoke whenever the active
backlog task carries the integration tag.
How it works
- Hook reads
<ai_hats_dir>/tracker/backlog/tasks/*/task.yamlfor any task inexecutestate. - If such a task has
- integrationin itstags:, it runspytest -m smoke -q --tb=line --no-header tests/e2e/. - All smoke tests pass → commit proceeds.
- Any test fails → commit blocked with a short report.
- No active task, or active task lacks the
integrationtag → silent no-op (exit 0). - pytest not installed or no tests marked
@pytest.mark.smoke→ silent pass.
Setting the integration tag
The agent decides during brainstorm or plan (see hatrack).
Heuristic: tag integration when the task touches an external tool, process,
network call, sub-agent invocation, or filesystem writes outside .agent/.
rack transition <ID> --append tags=integration
Override
AI_HATS_SMOKE_SKIP=1, exported by the supervisor in the shell that runs the
commit — see safety-guard for why you cannot write it yourself.
Pre-Push Force-Push Guard
The pre-push-shared-state.sh hook blocks a non-fast-forward (force) push —
an irreversible history rewrite. On a block, its message is the whole
instruction: the push did not happen, do not retry it, and do not set a flag.
A sentence in chat is not approval. safety-guard asks before the command
runs, where the harness can ask.
Other infra hooks (silent by design)
Two further pre-commit hooks ship here and stay out of the way unless tripped:
pre-commit-docs-index.sh— blocks adding/deleting/renaming adocs/*.mdwithout stagingdocs/INDEX.mdalongside.pre-commit-no-raw-destructive.sh— blocks rawpath.unlink/shutil.rmtree/.rmdiroutsideai_hats_core/safe_delete.pyunless the line carries# safe-delete: ok <reason>. No-op on non-ai-hats projects.
Hook Self-Heal (session start)
.githooks/ is generated by composition and not tracked in git, so it drifts
after git merge / git pull / git checkout. It is re-healed by the
session-start managed-hook drift net (WrapRunner._resync_managed_hooks):
on every ai-hats launch it re-materializes any drifted managed hook surface —
git and runtime (.claude/settings.json plus the scripts under the project's
<ai_hats_dir>/library/hooks/) — and prints a one-line note of
what it healed. Drift-gated and fail-open: a clean start is silent, a heal
failure never blocks the launch.
- There is no
ai-hats self sync-hookscommand and no post-merge / post-checkout git hook anymore (all healing is consolidated to session start). Agit pull+git commitwith no ai-hats launch between can run stale git hooks until the next launch heals them — launch ai-hats (orai-hats self init) to refresh sooner. - Bootstrap: a fresh clone still needs one initial
ai-hats self initto install hooks at all; they self-maintain on each launch after. - A "hooks corrupt" message on push means the gate's fail-closed dispatcher caught
a missing managed hook: run
ai-hats self initto repair.
Anti-Patterns
- Force push without approval — can destroy team members' work
- Giant commits mixing multiple concerns — keep commits atomic
- Commit messages describing what ("changed X") instead of why
- Committing agent config files to project repos — local agent state
- Committing empty/placeholder files — wait for real content
- Asking for a privacy-hook bypass (
AI_HATS_PRIVACY_ACK=1) without showing the user what was flagged — it is a peer review, not an obstacle (it exists because agents proved they could not catch leaks unaided) - Declaring "done" on integration work without running the real-path smoke test at least once
04 同仓库更多 Skills
tool-evaluation-protocol
Time-bounded protocol for evaluating new tools, libraries, or methodologies before adoption. Use when evaluating a candidate dependency for the project, researching a methodology (e.g. ML/LLM frameworks, testing approaches), or following up on a hype-driven recommendation.
systematic-debugging
4-phase bug-fix protocol (evidence, pattern, hypothesis, verify). Use when investigating any error, failure, or unexpected behavior, handling bug reports from users or monitoring, or diagnosing test failures with non-obvious causes.
skill-template
Canonical template and validation guide for ai-hats skills. Use when creating a new skill, reviewing an existing one for structural compliance, or deciding which pattern fits a new behavior.
skill-optimization
Audit and refactor library components to eliminate redundancy and staleness. Use during periodic library maintenance, after adding multiple new skills or rules, when a role's token budget is too high, or after retrospectives identify component issues.
silent-fallback-gate
PreToolUse hook — refuses an Edit or Write that adds an inert broad except. Use when a Python edit was blocked for a silent fallback.
retro-to-framework
Convert an observation about agent behavior — from a retrospective or from a single incident — into a framework-level change (hook, rule, skill, skill update). Use after a retrospective identifies problems that are not project-specific, after an incident where an agent misapplied a component it had read, when CLAUDE.md band-aids accumulate (more than 3 per-project rules that could be generic), or when the same problem recurs across multiple projects.