name: git-ops description: "Git operations orchestrator - commits, PRs, branch management, releases, changelog. Routes lightweight reads inline, dispatches heavy work to background Sonnet agent. Triggers on: commit, push, pull request, create PR, git status, git diff, rebase, stash, branch, merge, release, tag, changelog, semver, cherry-pick, bisect, worktree." allowed-tools: "Read Bash Glob Grep Agent TaskCreate TaskUpdate"
Intelligent git operations orchestrator. Routes read-only queries inline for speed, dispatches write operations to a background Sonnet agent (git-agent) to free the main session.
User intent (commit, PR, rebase, status, etc.)
|
+---> Tier 1: Read-only (status, log, diff, blame)
| |
| +---> Execute INLINE via Bash (fast, no subagent)
|
+---> Tier 2: Safe writes (commit, push, tag, PR, stash)
| |
| +---> Gather context from conversation
| +---> Dispatch to git-agent (background, Sonnet)
| | +---> Fallback: general-purpose with inlined protocol
| +---> Agent executes and reports back
|
+---> Tier 3: Destructive (rebase, reset, force-push, branch -D)
|
+---> Dispatch to git-agent (background, Sonnet)
| +---> Fallback: general-purpose with inlined protocol
+---> Agent produces PREFLIGHT REPORT (does NOT execute)
+---> Orchestrator relays preflight to user
+---> On confirmation: re-dispatch with execute authority
No subagent needed. Execute directly via Bash for instant results.
| Operation | Command |
|---|---|
| Status | git status --short |
| Log | git log --oneline -20 |
| Diff (unstaged) | git diff --stat |
| Diff (staged) | git diff --cached --stat |
| Diff (full) | git diff [file] or git diff --cached [file] |
| Branch list | git branch -v |
| Remote branches | git branch -rv |
| Stash list | git stash list |
| Blame | git blame [file] |
| Show commit | git show [hash] --stat |
| Reflog | git reflog --oneline -20 |
| Tags | git tag --list --sort=-v:refname |
| PR list | gh pr list |
| PR status | gh pr view [N] |
| Issue list | gh issue list |
| CI checks | gh pr checks [N] |
| Run status | gh run list --limit 5 |
For T1 operations, format results cleanly and present directly. Use delta for diffs when available.
Gather relevant context, then dispatch to git-agent (background, Sonnet).
Context gathering before dispatch:
| Operation | Context to Gather |
|---|---|
| Commit | What the user has been working on (from conversation), staged files, recent commit style |
| Push | Current branch, tracking info, commits ahead of remote |
| PR create | All commits on branch vs main, conversation context for description |
| Tag/release | Commits since last tag, version pattern in use |
| Stash | Current changes, user's stash message if provided |
| Cherry-pick | Target commit details, current branch |
| Branch create | Base branch, naming convention from recent branches |
| gh issue create | User description, labels if mentioned |
Dispatch template:
You are the git-agent handling a Tier 2 (safe write) operation.
## Context
- Current branch: {branch}
- Repository: {repo info}
- User intent: {what the user asked for}
- Conversation context: {relevant summary of what was being worked on}
## Operation
{specific operation details}
## Project Conventions
{commit style, branch naming, PR template if detected}
Execute the operation following your T2 protocol (verify state, execute, confirm, report).
Dispatch to git-agent with explicit instruction to produce a preflight report ONLY.
Dispatch template (preflight):
You are the git-agent handling a Tier 3 (destructive) operation.
## Context
- Current branch: {branch}
- Repository: {repo info}
- User intent: {what the user asked for}
## Operation
{specific operation details}
IMPORTANT: Do NOT execute this operation. Produce a T3 Preflight Report only.
Show exactly what will happen, what the risks are, and how to recover.
After user confirms: Re-dispatch with execute authority:
User has confirmed the Tier 3 operation after reviewing the preflight.
## Approved Operation
{exact operation from preflight}
## Confirmation
Proceed with execution. Follow T3 execution protocol:
1. Create a safety bookmark: note the current HEAD hash
2. Execute the operation
3. Verify the result
4. Report with the safety bookmark for recovery
# Dispatch to git-agent, runs in background, Sonnet model
Agent(
subagent_type="git-agent",
model="sonnet",
run_in_background=True, # Frees main session
prompt="..." # From dispatch templates above
)
The main session continues working while the agent handles git operations. Results arrive asynchronously.
For operations where the user is waiting on the result (e.g., "commit this then let's move on"):
Agent(
subagent_type="git-agent",
model="sonnet",
run_in_background=False, # Wait for result
prompt="..."
)
When the user explicitly asks for worktree isolation (e.g., "do this in a separate worktree", "prepare a branch without touching my working tree"):
Agent(
subagent_type="git-agent",
model="sonnet",
isolation="worktree", # Isolated repo copy
run_in_background=True,
prompt="..."
)
If git-agent is not registered as a subagent type (e.g., plugin not installed, agent files missing), fall back to general-purpose with the git-agent identity inlined in the prompt.
Detection: If dispatching to git-agent fails or the subagent type is not listed in available agents, switch to fallback mode automatically.
Fallback dispatch template:
Agent(
subagent_type="general-purpose", # Fallback
model="sonnet",
run_in_background=True,
prompt="""You are acting as a git operations agent. You are precise, safety-conscious,
and follow the three-tier safety system:
- T1 (read-only): execute freely
- T2 (safe writes): execute on instruction, verify before and after
- T3 (destructive): preflight report only unless explicitly told to execute
{original dispatch prompt here}
"""
)
Key differences from primary dispatch:
general-purpose instead of git-agent subagent typeWhen to use each:
| Condition | Dispatch Method |
|---|---|
git-agent available |
Primary: subagent_type="git-agent" |
git-agent unavailable |
Fallback: subagent_type="general-purpose" with inlined protocol |
| No agent dispatch possible | Last resort: execute T2 operations inline (main context) |
The last-resort inline path should only be used for simple T2 operations (single commit, simple push). Complex workflows (PR creation, release, changelog) should always use an agent.
When user asks to "create a release", "bump version", or "tag a release":
Inline (T1): Check current version and commits since last tag
git describe --tags --abbrev=0 2>/dev/null
git log --oneline $(git describe --tags --abbrev=0 2>/dev/null)..HEAD
Determine version bump:
feat: commits -> minor bumpfix: commits -> patch bumpBREAKING CHANGE: or !: -> major bumpDispatch to git-agent (T2): Tag, push tag, create GitHub release with generated notes
When user asks to "generate changelog" or "update CHANGELOG.md":
When user says "create a PR" or "open a PR":
When user asks to "clean up branches" or "delete merged branches":
bash
git branch --merged main | grep -v "main\|master\|\*"
When user asks "what should the next version be":
When user encounters merge conflicts:
git status to show conflicted filesWhen a git-related request arrives, follow this flow:
1. Classify the operation tier (T1/T2/T3)
2. If T1:
- Execute inline via Bash
- Format and present results
- DONE
3. If T2:
- Gather context (conversation, git state, conventions)
- Decide foreground vs background:
* User waiting on result? -> foreground
* User continuing other work? -> background
- Dispatch to git-agent with context
- Relay result when received
4. If T3:
- Gather context
- Dispatch to git-agent for PREFLIGHT ONLY
- Present preflight report to user
- Wait for explicit confirmation
- Re-dispatch with execute authority
- Relay result
| Task | Tier | Inline/Agent |
|---|---|---|
| Check status | T1 | Inline |
| View diff | T1 | Inline |
| View log | T1 | Inline |
| List PRs | T1 | Inline |
| Commit | T2 | Agent |
| Push | T2 | Agent |
| Create PR | T2 | Agent |
| Create tag | T2 | Agent |
| Create release | T2 | Agent |
| Stash push/pop | T2 | Agent |
| Cherry-pick | T2 | Agent |
| Create branch | T2 | Agent |
| Rebase | T3 | Agent (preflight) |
| Force push | T3 | Agent (preflight) |
| Reset --hard | T3 | Agent (preflight) |
| Delete branch | T3 | Agent (preflight) |
| Discard changes | T3 | Agent (preflight) |
| Merge to main | T3 | Agent (preflight) |
| Tool | Purpose |
|---|---|
git |
All git operations |
gh |
GitHub CLI - PRs, issues, releases, actions |
delta |
Syntax-highlighted diffs (if available) |
lazygit |
Interactive TUI (suggest to user, not for agent) |
For detailed patterns, load:
./references/rebase-patterns.md - Interactive rebase workflows and safety./references/stash-patterns.md - Stash operations and workflows./references/advanced-git.md - Bisect, cherry-pick, worktrees, reflog, conflicts