3 +description: Use for Git repository workflows: committing changes, rebasing/pushing fast-forward, landing branches, or reviewing PRs. Load when a prompt says git workflow or when jj is not active.
8 +Use Git only after `jj root` fails. Preserve unrelated dirty work. Never force-push.
12 +- Inspect before mutating: `git status --short --branch`.
13 +- Stop on merge/rebase/cherry-pick conflicts unless the user explicitly asks to continue.
14 +- Read untracked files before staging them.
15 +- Exclude generated/cache/secret files. Ask only if ambiguous.
16 +- Run obvious fast checks when available; skip expensive/unclear checks with reason.
17 +- No AI attribution/trailers.
24 +git symbolic-ref refs/remotes/origin/HEAD
2>/dev/null
| sed
's|refs/remotes/[^/]*/||' 27 +If empty: `git remote set-head origin --auto`, retry. Fallback: first existing local or remote ref from `trunk`, `main`, `master`, `develop`. If none: stop and ask.
31 +1. Inspect: `git status --short --branch`, `git diff --stat && git diff`, and if staged `git diff --cached --stat && git diff --cached`.
33 +3. Split unrelated changes into focused commits when safe; otherwise ask.
34 +4. Stage relevant files only.
35 +5. Commit. If hooks change files, inspect, restage, retry once.
37 +7. Report hash, subject, checks.
41 +- Short, concrete subject. Subject-only OK.
42 +- Prefer `add`, `fix`, `update`, `remove`, `replace`, `track`, `show`, `rework`.
43 +- Use `type(scope): summary` when natural: `feat`, `fix`, `docs`, `chore`, `refactor`, `test`, `perf`, `build`, `ci`.
44 +- Use domain prefix when clearer: `ui: ...`, `db: ...`, `cli: ...`, `docs: ...`.
45 +- Lowercase after prefix. No final period.
46 +- Body only when useful: bullets, rationale, tests.
47 +- Preserve issue IDs. If exactly one issue is referenced in conversation history or branch name, include `closes #<N>`. Multiple issues → ask which. None → omit.
49 +##
Fast-forward branch (`ff`) 51 +Goal: rebase current branch onto target/default branch and push current branch. Linear history only.
53 +Args: `$1` may be target branch if it names an existing local/remote ref. Remainder is test command.
55 +1. Preflight: clean tree, no ongoing operation, not detached HEAD. Record branch and remote (`origin`).
56 +2. Fetch: `git fetch --prune --tags <remote>`.
57 +3. Rebase onto target: record `git rev-list --count <remote>/<target>..HEAD`; warn if >50; run `git rebase <remote>/<target>`; compare count after and warn if fewer commits.
58 +4. Conflicts → stop; show files, status, next commands.
59 +5. Test: run provided command or infer cheap checks.
60 +6. Push: `git push <remote> <branch>`. If rejected: fetch, rebase once, retest, retry once. Never force-push.
61 +7. Report branch, target, remote, rebase yes/no, tests, pushed SHA, follow-up.
63 +##
Land branch (`lm`) 65 +Goal: fast-forward target/default branch to current branch tip and push target.
67 +1. Preflight: clean tree, no ongoing operation, on a branch that is not target. Already on target → tell user to use `ff`.
68 +2. Fetch: `git fetch --prune --tags <remote>`.
69 +3. Verify ancestor: `git merge-base --is-ancestor <remote>/<target> HEAD`. Fail → target has commits not in current branch; tell user to run `ff` first.
70 +4. Warn if branch commits lack `closes #<N>` but conversation mentions an issue.
71 +5. Test: run provided command or infer cheap checks.
72 +6. Fast-forward target: `git update-ref refs/heads/<target> HEAD <old-target-sha>`.
73 +7. Push: `git push <remote> <target>`. If rejected: fetch, verify ancestor, retry once.
74 +8. Offer to delete landed branch.
75 +9. Report branch → target, old/new target SHA, tests, pushed SHA, follow-up.
79 +Do not merge until explicit user OK.
81 +1. Resolve PR from argument or conversation. If none: ask.
82 +2. Detect forge CLI from remote URL: `github.com` → `gh`; `codeberg.org` or Forgejo → `fj`; bare git server → generic Git. Missing CLI → generic Git.
83 +3. Resolve metadata: title, author, base, head, URL, status, CI, labels.
84 +4. Protect local work: dirty unrelated work → prefer isolated `git worktree`.
85 +5. Fetch latest base/head.
86 +6. Checkout via worktree when dirty or isolation needed; otherwise branch checkout when clean. Use forge CLI for metadata/merge only; use Git-native fetch/checkout for files.
87 +7. Review diff: `git diff <base>...<head>`. Read relevant files, tests, docs, configs. Check correctness, security, perf, API compat, migrations, UX, error handling, issue match.
88 +8. Test provided command or infer from project files.
89 +9. Report summary, checkout location, base/head SHAs, blockers/warnings/notes with file:line refs, tests, readiness `READY|NOT READY`, exact merge plan.
90 +10. Wait. On explicit OK: re-fetch, verify current/mergeable, run critical checks, merge via forge CLI or Git-native fast-forward preferred, report final status. Offer cleanup.