You are merging a feature branch from a worktree into the appropriate versioned dev branch (vN/dev) and cleaning up afterwards. This is for lightweight changes that don't warrant a GitHub PR.
-
Determine which worktree to merge.
If the user provides an argument, use it as the worktree name or branch name.
If no argument is provided, first check if the current working directory is inside a worktree:
MAIN_ROOT=$(git worktree list | head -1 | awk '{print $1}')
CWD=$(pwd)
If CWD is inside a .claude/worktrees/ path (i.e., we're currently in a worktree), extract the worktree name and ask the user: "You're currently in worktree <name> — merge this one?" If they confirm, use it. If they decline, fall through to the list.
If not in a worktree (or user declined), list all worktrees and ask the user which one to merge:
git worktree list
Exclude the main worktree (the first entry). If there are no worktrees, tell the user and stop.
-
Determine the branch name from the worktree. Check what branch the worktree is on:
git -C <worktree-path> branch --show-current
-
Check for uncommitted changes in the worktree:
git -C <worktree-path> status --short
If there are uncommitted changes, warn the user and ask whether to proceed (changes will be lost) or stop so they can commit first.
-
Switch to the main repo root if currently inside the worktree:
cd <main-repo-path>
-
Determine the target dev branch from the feature branch name. The version prefix of the feature branch dictates the target:
v18/feature/foo → merge into v18/dev
v17/feature/bar → merge into v17/dev
Extract the prefix:
version_prefix=$(echo "<branch-name>" | grep -oP '^v\d+')
target_dev="${version_prefix}/dev"
If the branch name doesn't start with vN/, ask the user which version's dev branch to target.
-
Ensure the target dev branch is up to date:
git checkout $target_dev
git pull origin $target_dev
-
Merge the feature branch with a merge commit:
git merge --no-ff <branch-name>
If there are merge conflicts, report them and stop — let the user resolve them.
-
Push:
git push origin $target_dev
-
Clean up by invoking the worktree-cleanup skill:
/worktree-cleanup <worktree-name>
-
Show a summary:
- Branch merged
- Commit(s) merged (short log)
- Worktree and branch cleaned up
- Current state (on
$target_dev, pushed)