--- description: Rebase current branch onto default branch and push fast-forward argument-hint: "[target-branch] [test-command]" --- # Rebase onto default branch and push fast-forward One flow. Works the same for git and jj. Linear history only. No merge commits. No force-push. ## Args - `$1` → target branch if it names an existing local/remote ref. Remainder → test command. - No arg → auto-detect default branch, no tests. ## Detect default branch Never assume a name. Detect dynamically: **Git:** `git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's|refs/remotes/[^/]*/||'` Empty → `git remote set-head origin --auto` → retry. Fallback: `trunk` → `main` → `master` → `develop` (first existing local or remote ref wins). All fail → stop, ask user. **jj:** `jj bookmark list 'trunk()'` — uses configured trunk revset. Empty → try `trunk@origin` → `main@origin` → `master@origin`. All fail → stop, ask user. --- ## Flow Decide git or jj: `jj root` succeeds → jj, else git. 1. **Preflight** - Git: `git status --short --branch`. Stop if dirty tree or ongoing merge/rebase. `git branch --show-current`. Stop if detached HEAD (empty output). - Jj: `jj status`. Stop on conflicts. - Record: current branch/bookmark, remote (default `origin`). 2. **Fetch** - Git: `git fetch --prune --tags `. - Jj: `jj git fetch --remote `. 3. **Rebase onto target** - Before: record commit count on branch (`git rev-list --count /..HEAD` / `jj log -r '..@ --template ''` + count). If >50 → warn, proceed. - Git: `git rebase /`. - Jj: `jj rebase -b @ -o `. - After: compare commit count. Fewer → warn (empty commits dropped). - Conflicts → stop; show files, status, next commands. - Already up-to-date → skip, note in report. 4. **Test** Run given command, or infer cheap checks from project files. Failure → stop, no push. 5. **Push** - Git: `git push `. - Jj: `jj bookmark move --to @` (if behind), then `jj git push --bookmark `. - Rejected → fetch, rebase once, retest, retry **once**. - Retry also rejected → stop. Report error (likely branch protection or remote history rewrite). - Never force-push. --- ## Report branch, target, remote, rebase yes/no, tests, pushed SHA, follow-up.