--- name: git-workflow path: .git description: "Use for Git commits, branch/commit reviews, pull/sync/rebase, fast-forward integration, or authorized pushes." --- # Git workflow Read every section the request touches; each section defines its own authority. Routing grants no authority to commit, rebase, or publish. In colocated Git/Jujutsu workspaces, use the VCS the user or project selected; ask if ambiguous before mutating. GitHub PR operations and planning merges in dirty trees are out of scope here. ## Shared rules - Preserve unrelated work; never force-push; never bypass hooks autonomously. - Mutating operations require a clean tree (except commit), an attached branch, and no merge, rebase, cherry-pick, or revert in progress, unless the request explicitly covers that operation. - Resolve the remote from the current branch's configured upstream; with no upstream, use the sole configured remote; ask when several exist. - Resolve an explicit target first; otherwise the remote's symbolic HEAD, then the first existing remote branch among `trunk`, `main`, `master`, `develop`. Do not mutate remote configuration merely to discover the target. - Run repository-required gates plus requested or obvious fast checks; stop when a required check fails; report expensive or unclear checks not run. - If a hook fails, preserve its edits and stop with the failing command and evidence. ## Commit Commit selected work without pushing. 1. Inspect `git status --short --branch`, the unstaged diff, and any staged diff; stop if clean. 2. Read relevant untracked files before deciding whether to stage them. Exclude generated files, caches, secrets, and unrelated work. 3. Split unrelated changes into focused commits when safe; otherwise ask. 4. Run checks, stage only the intended paths, and inspect the complete staged diff. 5. Commit without pushing. If a hook only formats relevant files, inspect and restage those files, then retry once. 6. Report the commit hash, subject, checks, and remaining working-tree state. Messages: - Terse, concrete imperative subject without a final period. - One action and one conceptual object; name the shared user-facing purpose, not joined UI properties, locations, or implementation details. - Security or data-loss subjects state any irreversible user constraint as a warning, with a direct action plus finite clause. - Prefer `add`, `fix`, `update`, `remove`, `replace`, `track`, `show`, or `rework`. - Use `type(scope): summary` when natural: `feat`, `fix`, `docs`, `chore`, `refactor`, `test`, `perf`, `build`, or `ci`. - Use a domain prefix such as `ui:`, `db:`, `cli:`, or `docs:` when clearer; start the text after a prefix lowercase. - Body only when rationale or non-obvious constraints matter. - Preserve relevant work-item identifiers supplied by the user or repository policy. - No AI attribution or trailers. ## Review Read-only: no source edits, commits, pushes, merges, or published feedback. Fetching refs and creating an isolated worktree for tests are allowed. 1. Resolve base and head; ask when the comparison is ambiguous. 2. Record the caller's branch, working-tree state, and exact resolved commit IDs; fetch requested remote revisions, then pin them. 3. Preserve the caller's checkout; inspect pinned objects directly or use an isolated worktree for tests. 4. Produce the exact `base...head` diff and inspect relevant source, callers, tests, documentation, and configuration. 5. Run requested checks in the isolated worktree. 6. Report pinned commits, comparison, checkout location, and checks without applying review or approval policy; stop there. ## Sync Fetch, rebase, test; push only when publication was requested. 1. Record the current branch, remote, target, and current commit. 2. Fetch the remote with pruning and tags. 3. Count commits above the remote target; warn before rebasing more than 50. 4. Rebase onto the fetched target. On conflicts, stop and report conflicted files, status, and exact continue or abort choices. 5. Compare the resulting stack with the recorded stack; report unexpectedly dropped commits. 6. Run checks. 7. Without publication authorization, stop after local synchronization. 8. Push the current branch normally. If rejected, fetch, rebase, and test once more, then retry once. 9. Report branch, target, remote, whether a rebase occurred, checks, publication authorization, any pushed commit, and a web link to each CI run the push triggered. Interrupted rebases and autostash: - With `rebase.autostash` or `merge.autostash`, an interrupted fetch, rebase, merge, or pull (failing hook or filter, aborted or timed-out command) silently leaves work in a stash entry named `autostash`; affected files look modified or deleted. - After any such interruption, run `git stash list` before touching the worktree. - Treat an `autostash` entry you did not create as unrestored work: inspect with `git stash show -p`, restore with `git stash apply`, drop only once its content is confirmed present. - Never commit deletions Git reports after such a failure; recover the stash first. - Prefer committing before synchronizing, so autostash never triggers. ## Fast-forward Advance a target branch to the current commit without a merge commit, only when the fetched target is an ancestor of the current commit. Never discard local target work. 1. Refuse when the current branch is the target; sync that branch instead. 2. Fetch the remote with pruning and tags. 3. Verify the fetched remote target is an ancestor of the current commit; otherwise stop and require sync first. 4. If a local target branch exists: stop if it has commits absent from the fetched remote target or is checked out in another worktree; do not move it before the remote update. 5. Require explicit authorization to advance the target. 6. Run checks. 7. Push the current commit to the target with a normal explicit refspec. If rejected, fetch and repeat the ancestry check once before one retry. 8. After a verified push, optionally fast-forward an unoccupied local target; never overwrite a divergent or locally advanced target. 9. Offer scoped deletion of the integrated source branch; never delete it automatically. 10. Report source, target, remote, old and new target commits, checks, push result, local-target state, and a web link to each CI run the push triggered.