How this skill is triggered — by the user, by Claude, or both
Slash command
/git:rebase [base-branch][base-branch]This skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Rebase the current feature branch onto the default branch (typically `main`), with interactive per-conflict prompts and an automatic backup branch so nothing is lost if the rebase goes sideways. Complements `/git:create` (rebase locally → then open a squash-merge PR with a clean linear history). The design follows the "golden rule of rebasing" from Pro Git ([git-scm.com](https://git-scm.com/boo...
Rebase the current feature branch onto the default branch (typically main), with interactive per-conflict prompts and an automatic backup branch so nothing is lost if the rebase goes sideways. Complements /git:create (rebase locally → then open a squash-merge PR with a clean linear history). The design follows the "golden rule of rebasing" from Pro Git (git-scm.com): rebase locally before pushing; never rebase commits that are already shared.
Read CLAUDE.md and AGENTS.md at the repo root in parallel if they exist. Absorb naming, commit conventions, and language rules before drafting anything.
Run these in parallel:
git status --porcelaingit branch --show-currentgit rev-parse HEADgit rev-parse --abbrev-ref @{u} 2>/dev/null (detects whether the branch has an upstream — empty output means it doesn't)Save the original commit count for later verification (run git log --oneline <base>..HEAD | wc -l once <base> is known).
In order:
If the working tree is not clean (any output from git status --porcelain), stop with: Working tree is dirty. Commit or stash changes, then retry. List the dirty paths. Never auto-stash.
Resolve the base branch:
gh repo view --json defaultBranchRef -q .defaultBranchRef.name
If gh is unavailable or fails, fall back to main. If the user passed an argument ([base-branch]), use that instead. Store as <base>.
If the current branch equals <base>, stop with: Already on <base>. Switch to a feature branch first.
If the branch has zero commits ahead of <base> (git log --oneline <base>..HEAD is empty), stop with: Branch is already at parity with <base>. Nothing to rebase.
Golden rule check — if step 2 found an upstream, warn explicitly:
This branch is already pushed. Rebasing rewrites history — anyone who has pulled these commits will need to re-sync. Continue only if you're the sole user of this branch (typical for solo feature branches in a squash-merge workflow).
Then ask via AskUserQuestion:
Build a UTC-timestamped backup branch name: backup/<current-branch>-<YYYYMMDDTHHMMSSZ>. Example: backup/feat-rebase-skill-20260524T130000Z.
git branch <backup-name>
Backup is local only — never auto-pushed. Tell the user explicitly:
Backup created at
<backup-name>. To restore at any point:git reset --hard <backup-name>.
git fetch origin <base>
Then show the ahead/behind counts:
git rev-list --left-right --count HEAD...origin/<base>
Format as: Your branch: N ahead, M behind origin/<base>.
Show the user the list of commits that will be replayed:
git log --oneline origin/<base>..HEAD
Then ask via AskUserQuestion:
git branch -D <backup-name> to clean up the now-unused backupgit rebase origin/<base>
If this completes without conflicts, skip to step 9.
While git status reports rebase in progress (detect via git status --porcelain | grep -E '^(UU|AA|DD|AU|UA|UD|DU)'):
a. List conflicted files:
git diff --name-only --diff-filter=U
b. For EACH conflicted file (one at a time, do not batch):
Read tool to see the conflict markers (<<<<<<<, =======, >>>>>>>).<<<<<<< and =======).<base> — between ======= and >>>>>>>).AskUserQuestion:
<base>Edit and show the result for confirmation before moving ongit rebase --abort, then tell the user the backup branch is intact and how to use git reset --hard <backup-name> if they want to walk back furthergit checkout --ours <file> && git add <file> (Bash). For (b): git checkout --theirs <file> && git add <file>. For (c): use Edit to write the resolved content, then git add <file>. For (d): stop the whole skill.c. Once every conflicted file in the current step is resolved (no more U entries in git status):
git rebase --continue
d. If --continue triggers a new conflict (Git replays the next commit and it conflicts too), loop back to (a). If --continue finishes cleanly, exit the loop.
Run:
git log --oneline <base>..HEAD
Compare the commit count to what was saved in step 2.
Replay complete: N commits replayed cleanly.WARNING: was N commits, now M commits. Some commits may have been dropped or squashed. Inspect the diff vs. the backup branch before pushing.Always show the cumulative diff summary vs. the backup:
git diff <backup-name>..HEAD --stat
Ask via AskUserQuestion:
(a) Push now with --force-with-lease (Recommended) — runs:
git push --force-with-lease origin <current-branch>
Never plain --force. If the push fails because the lease was broken (someone else pushed), surface the error, do NOT retry, and tell the user to investigate.
(b) Stop here — print the new HEAD short hash, the backup branch name, and the exact push command above for the user to run later.
Always print, even when (b) was chosen at step 10:
git rev-parse --short HEAD)git diff <backup-name>..HEAD carefully before deleting the backup."git branch -D <backup-name>."git push --force — always --force-with-lease. The "lease" refuses the push when the remote moved since the last fetch, so a teammate's push isn't silently overwritten.AskUserQuestion.--no-verify, --strategy=ours, --strategy=theirs, or any other lossy auto-resolution flag on git rebase.git rebase.AskUserQuestion per file. Never batch.Guides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.
npx claudepluginhub shoto290/shoto --plugin git