Rebase the current branch onto a target branch using safety checks and an appropriate rebase strategy. Use when invoked as `$git-rebase` or when the user asks to update/rebase a branch.
86%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
Rebase the current branch onto a target branch. If the user provides an argument, use it as the target branch; otherwise use the remote default branch.
Gather context:
subject=$(git branch --show-current)
target=<argument-or-default-branch>
git status --porcelain=v1Stop if:
subject equals target.Fetch remote-tracking refs without touching the local target branch:
git fetch origin --prune
target_ref="origin/${target}"Never use git fetch origin "${target}:${target}" for a branch that may be checked out in another worktree. If a local target branch must be updated, do that only in the worktree that currently has it checked out.
Analyze divergence:
merge_base=$(git merge-base HEAD "${target_ref}")
git log --oneline "${merge_base}..HEAD"
git log --oneline "${merge_base}..${target_ref}"
git diff --name-only "${merge_base}" HEAD
git diff --name-only "${merge_base}" "${target_ref}"
git merge-base --is-ancestor "${merge_base}" "${target_ref}" && echo base_on_target=yes || echo base_on_target=noChoose strategy:
| Condition | Strategy |
|---|---|
| Target has at least 20 commits and at least 3 overlapping files | cherry-pick |
| Merge-base is not on target lineage | rebase --onto |
| Otherwise | simple rebase |
Show the analysis and selected strategy before proceeding.
Execute:
git rebase "${target_ref}"git rebase --onto "${target_ref}" "${merge_base}" HEAD<subject>__cherrypick__ from target_ref and cherry-pick subject commits oldest-first.On conflicts, resolve automatically and continue; rerere makes this recoverable:
rerere resolution..codex/*.config.toml trust hashes): keep ours (git checkout --ours); the clean filter re-normalizes the blob on git add.--skip the commit if the bump is already upstream.git checkout --theirs).Stage each fix, verify no conflict markers remain, then --continue (or --skip if the commit became empty). Pause and ask only for genuine semantic collisions in hand-written source — never guess those. Report how each conflict was resolved.
After success, set tracking and push:
git branch --set-upstream-to="origin/${subject}" "${subject}"
git push --force-with-lease -u origin "${subject}:${subject}"
git branch -vvReport strategy, branch, and tracking.
phatblat/dotfiles
4d65cab
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.