--- description: Sync current git/jj branch into trunk via rebase + fast-forward argument-hint: "[trunk] [test-command]" --- # Sync current git/jj branch into trunk via rebase + fast-forward Sync current branch/bookmark into trunk. Linear history only. No merge commits. Never force-push trunk. Args: if `$1` is branch/ref/bookmark → trunk, `${@:2}` → tests. Else infer trunk, `$ARGUMENTS` → tests. If `jj root` succeeds, use jj: 1. Inspect: `jj status`, `jj bookmark list`, `jj git remote list`, `jj log -r '..@'`. 2. Stop on conflicts, dirty unrelated working-copy change, ambiguous trunk/bookmark, or non-git-backed jj repo when push is needed. 3. Fetch/update: `jj git fetch --remote `. 4. Rebase current stack if needed: `jj rebase -b @ -o `. 5. Test as below. 6. Fast-forward trunk bookmark: `jj bookmark move --to @` (never `--allow-backwards`). 7. Push: `jj git push --remote --bookmark `. On reject: fetch, re-evaluate, rebase once if safe, retest, retry. 8. Report: trunk/remote, change old→new, rebase yes/no, tests, pushed change, follow-up. Otherwise use git: 1. Inspect - Run: `git status --short --branch`, `git branch --show-current`, `git remote -v`, `git worktree list --porcelain`, `git branch -vv`. - Stop on: non-git, detached HEAD, merge/rebase in progress, dirty index/worktree, dirty trunk worktree. - Record: branch, upstream, remote, trunk, HEAD. 2. Find trunk - Prefer arg. - Else infer: upstream/base metadata → remote HEAD → `main` → `master` → `trunk` → `develop`. - Ambiguous → ask. - If trunk checked out in worktree, use that worktree for trunk ops. 3. Fetch/update trunk - `git fetch --prune --tags `. - If trunk worktree: `git -C pull --ff-only`. - Else if local trunk exists: `git fetch :` (no `+`). - Else create from remote: `git branch --track /`. - Trunk divergence → stop. 4. If already on trunk - `git pull --ff-only`. - Run tests if given/obvious. - Push if ahead: `git push `. - Report. 5. Rebase branch - Check diff/log: `git log --oneline --left-right --cherry-pick ...HEAD`, `git diff --stat ...HEAD`. - If needed: `git rebase `. - Conflict → stop; show status/files/next commands. - Verify branch still has intended commits/diff. 6. Test - Run supplied test cmd, else cheap obvious checks from project files. - Failure → stop. No merge/push. 7. Fast-forward trunk - Require: `git merge-base --is-ancestor HEAD`. - If trunk worktree: `git -C merge --ff-only `. - Else: `git update-ref refs/heads/ HEAD `. 8. Push - `git push `. - Rejected → fetch, re-evaluate, rebase once if safe, retest critical checks, retry. - Never force-push trunk. Report: trunk/remote, branch old→new SHA, rebase yes/no, tests, pushed SHA, follow-up.