chore(skills): add worktree-update skill
Non-destructive branch sync utility. On main: shows worktree branches ahead of main with PR flags, lets user pick which to merge. On other branches: merges main in. Stops on conflicts, never force-pushes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,109 @@
|
|||||||
|
---
|
||||||
|
name: worktree-update
|
||||||
|
description: >
|
||||||
|
Sync worktree branches with main. Use when the user says "update worktrees",
|
||||||
|
"sync branches", "merge main", "worktree update", or invokes /worktree-update.
|
||||||
|
When on main: shows which worktree branches are ahead and lets the user pick
|
||||||
|
which to merge into main (flags branches with open PRs). When on a non-main
|
||||||
|
branch: merges main into the current branch. All operations are non-destructive.
|
||||||
|
user-invocable: true
|
||||||
|
allowed-tools: Bash, Read, AskUserQuestion
|
||||||
|
---
|
||||||
|
|
||||||
|
# Worktree Update Skill
|
||||||
|
|
||||||
|
Sync worktree branches safely. Direction depends on the current branch.
|
||||||
|
|
||||||
|
## Safety Rules (NON-NEGOTIABLE)
|
||||||
|
|
||||||
|
- **Never force-push, reset --hard, rebase, or delete branches.**
|
||||||
|
- **Never use `--no-verify` or skip hooks.**
|
||||||
|
- **Always use `--no-edit` on merges** to avoid interactive editor prompts.
|
||||||
|
- **Stop on merge conflicts** — report them and let the user decide. Never
|
||||||
|
auto-resolve or abort a conflicted merge without asking.
|
||||||
|
- **Fetch before comparing** — always `git fetch --all` first so commit
|
||||||
|
comparisons are accurate.
|
||||||
|
- **Dry-run first on main** — show the user exactly what will happen before
|
||||||
|
merging anything into main.
|
||||||
|
|
||||||
|
## Workflow
|
||||||
|
|
||||||
|
### 1. Detect current branch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git branch --show-current
|
||||||
|
```
|
||||||
|
|
||||||
|
Branch determines the mode: `main` → outbound sync, anything else → inbound sync.
|
||||||
|
|
||||||
|
### 2a. On `main` — merge worktree branches into main
|
||||||
|
|
||||||
|
#### Fetch and compare
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git fetch --all
|
||||||
|
```
|
||||||
|
|
||||||
|
For each worktree branch, check if it has commits ahead of main:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git rev-list --count main..<branch>
|
||||||
|
```
|
||||||
|
|
||||||
|
Skip branches with 0 commits ahead. For branches that ARE ahead, collect:
|
||||||
|
- Branch name
|
||||||
|
- Number of commits ahead
|
||||||
|
- One-line log of those commits: `git log --oneline main..<branch>`
|
||||||
|
|
||||||
|
#### Check for open PRs
|
||||||
|
|
||||||
|
```bash
|
||||||
|
tea pr list --login schweitz --repo jpmschweitzer/settled-reach --state open --output simple
|
||||||
|
```
|
||||||
|
|
||||||
|
Cross-reference open PR head branches with the ahead-of-main branches.
|
||||||
|
|
||||||
|
#### Present results
|
||||||
|
|
||||||
|
Show a summary table of branches ahead of main. For each branch, indicate:
|
||||||
|
- `[PR]` if it has an open pull request — warn that it should go through
|
||||||
|
normal review channels (use `/review-pr` instead)
|
||||||
|
- Commit count and summary
|
||||||
|
|
||||||
|
Use `AskUserQuestion` to let the user pick which branches to merge.
|
||||||
|
Exclude PR-flagged branches from the default options (but allow the user to
|
||||||
|
override via "Other").
|
||||||
|
|
||||||
|
#### Merge selected branches
|
||||||
|
|
||||||
|
For each selected branch, one at a time:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git merge <branch> --no-edit
|
||||||
|
```
|
||||||
|
|
||||||
|
If a merge conflicts, **stop immediately**. Report the conflict and do NOT
|
||||||
|
continue to the next branch. The user must resolve before proceeding.
|
||||||
|
|
||||||
|
After all merges, show the final state with `git log --oneline -N` (where N
|
||||||
|
covers the new commits).
|
||||||
|
|
||||||
|
### 2b. Not on `main` — merge main into current branch
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git fetch --all
|
||||||
|
git merge origin/main --no-edit
|
||||||
|
```
|
||||||
|
|
||||||
|
If clean, report the result (fast-forward or merge commit, files changed).
|
||||||
|
If conflicts, report them and stop.
|
||||||
|
|
||||||
|
### 3. Push prompt
|
||||||
|
|
||||||
|
After a successful merge, ask the user if they want to push:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
git push origin <current-branch>
|
||||||
|
```
|
||||||
|
|
||||||
|
Never push without explicit confirmation.
|
||||||
Reference in New Issue
Block a user