worktree-end
Skill0 starsChanged 9 months agoMITView on GitHub
Completes a worktree by checking for uncommitted changes, pushing to remote, merging to main, and removing the worktree. Use when finishing work on a feature.
- Commits and pushes
In this repository18 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adr-createSkill
- dev-log-rotateSkill
- discovery-startSkill
- gather-insightSkill
- git-commitSkill
- init-projectSkill
- insight-captureSkill
- jira-startSkill
- review-implementationSkill
- session-endSkill
- session-listSkill
- session-startSkill
- team-stream-startSkill
- work-stream-startSkill
- worktree-listSkill
- worktree-removeSkill
- worktree-startSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
23 rules. About 0 are common, 22 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈22
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 24
Must be in the main repository (not in the worktree being ended)
- Distinctive: line 41
If user didn't specify which worktree, use AskUserQuestion:
- Distinctive: line 66
Cancel: - Stop and let me handle it manually
- Distinctive: line 69
Ask for commit message
- Distinctive: line 83
Check if remote tracking exists:
- Distinctive: line 103
Cancel: - Stop and investigate
- Distinctive: line 114
Check if branch has been merged to main:
- Distinctive: line 125
Run rebase from the worktree:
- Distinctive: line 147
Stop skill execution (do NOT proceed to merge or removal)
- Distinctive: line 154
After successful rebase, perform fast-forward merge:
- Distinctive: line 195
Delete local only: - Keep remote branch
- Distinctive: line 196
Keep branch: - Don't delete anything
- Distinctive: line 210
Do nothing, branch remains
- Distinctive: line 247
Do NOT attempt to resolve conflicts
- Distinctive: line 252
Check if VS Code or other process has files open
- Very specific: line 257
If -d fails (not fully merged): explain and offer -D
- Distinctive: line 258
If remote deletion fails: show error, continue with local deletion
- Distinctive: line 265
Uncommitted changes check: Always check and prompt before proceeding
- Distinctive: line 269
Graceful failure: If any step fails, provide recovery options
- Distinctive: line 270
Main protection: Only merges INTO main via ff-only, never force-pushes main
- Distinctive: line 363
Always run from main repository, not from within a worktree
- Distinctive: line 366
If rebase conflicts, skill aborts and preserves worktree for manual resolution
- Distinctive: line 367
If anything fails, branch is safely on remote for recovery
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Worktree End Skill
Completes a worktree workflow by safely finishing all work, pushing to remote for backup, merging into main, and cleaning up the worktree.
When to Use
Activate this skill when:
- User wants to finish/complete a worktree and merge the work
- User says "end worktree", "finish worktree", "complete worktree", or "merge worktree"
- User has completed work on a feature and wants to integrate it
- User wants to merge a worktree branch and clean up
For abandoned work or simple removal without merging, use /worktree-remove instead.
Prerequisites
- Must be in the main repository (not in the worktree being ended)
- Work in the worktree should be complete (all changes committed)
- Remote should be configured (for push step)
Instructions
Step 1: Get Available Worktrees
Run:
git worktree listParse output to get list of worktrees (excluding main).
Step 2: Ask Which Worktree to End
If user didn't specify which worktree, use AskUserQuestion:
Question: "Which worktree do you want to end and merge?"
- List available worktrees as options
- Show branch name for each
Step 3: Check for Uncommitted Changes
For the selected worktree, run:
git -C "[worktree-path]" status --porcelainIf there are uncommitted changes:
- Show the list of changed files
- Use AskUserQuestion:
Options:This worktree has uncommitted changes: - [list of files] What would you like to do?- Commit changes - I'll commit them with a message you provide
- Discard changes - Proceed anyway (changes will be lost)
- Cancel - Stop and let me handle it manually
If "Commit changes" selected:
- Ask for commit message
- Run:
git -C "[worktree-path]" add -A && git -C "[worktree-path]" commit -m "[message]"
If "Discard changes" selected:
- Run:
git -C "[worktree-path]" checkout -- . - Continue to next step
If clean:
- Proceed to next step
Step 4: Push Branch to Remote (Safety Backup)
Get the branch name from the worktree.
Check if remote tracking exists:
git -C "[worktree-path]" rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/nullIf no remote tracking:
git -C "[worktree-path]" push -u origin [branch-name]If remote tracking exists:
git -C "[worktree-path]" pushIf push fails:
- Show error message
- Use AskUserQuestion:
- Retry - Try pushing again
- Skip push - Continue without pushing (not recommended)
- Cancel - Stop and investigate
Display: "Branch pushed to remote for safety backup."
Step 5: Rebase Branch onto Main
First, fetch latest from remote:
git fetch origin mainCheck if branch has been merged to main:
git branch --merged main | grep "[branch-name]"If already merged:
- Display: "Branch is already merged to main. Skipping rebase/merge step."
- Proceed to worktree removal
If NOT merged:
- Display: "Rebasing [branch-name] onto main for clean history..."
- Run rebase from the worktree:
git -C "[worktree-path]" rebase main
If rebase conflicts:
- Abort the rebase immediately:
git -C "[worktree-path]" rebase --abort - Display:
Rebase conflict detected. Aborting rebase. The worktree has NOT been modified. Please resolve this manually in the worktree: 1. cd [worktree-path] 2. git rebase main 3. Resolve conflicts 4. git rebase --continue 5. Run /worktree-end again - Stop skill execution (do NOT proceed to merge or removal)
If rebase succeeds:
- Display: "Successfully rebased [branch-name] onto main."
Step 6: Fast-Forward Merge
After successful rebase, perform fast-forward merge:
git merge --ff-only [branch-name]If ff-only fails (shouldn't happen after rebase, but safety check):
- Display error message
- Suggest manual resolution
- Stop skill execution
If merge succeeds:
- Display: "Fast-forward merged [branch-name] into main (clean linear history)."
Step 7: Push Main to Remote
After successful merge:
git push origin mainDisplay: "Pushed updated main to remote."
Step 8: Remove Worktree
Run:
git worktree remove "[worktree-path]"Verify removal succeeded.
Display: "Worktree removed: [worktree-path]"
Step 9: Ask About Branch Deletion
Use AskUserQuestion:
Question: "Do you want to delete the branch '[branch-name]'?"
Options:
- Delete local and remote (Recommended) - Clean up completely
- Delete local only - Keep remote branch
- Keep branch - Don't delete anything
If "Delete local and remote":
git branch -d [branch-name]
git push origin --delete [branch-name]If "Delete local only":
git branch -d [branch-name]If "Keep branch":
- Do nothing, branch remains
Step 10: Confirm Completion
Display summary:
Worktree ended successfully!
Summary:
- Worktree removed: ../[worktree-name]
- Branch rebased and fast-forward merged: [branch-name] -> main
- History: Clean linear (no merge commits)
- Branch status: [deleted / kept]
- Remote: [pushed / skipped]
Remaining worktrees: [N]Error Handling
If not in main repository:
- Detect if current directory is a worktree (not main)
- Error: "You appear to be in a worktree. Run this skill from the main repository."
- Suggest: "Navigate to [main-repo-path] and try again."
If worktree doesn't exist:
- Error: "Worktree not found. Use /worktree-list to see available worktrees."
If push fails (network/auth):
- Show error message
- Offer to skip push and continue (with warning)
- Offer to cancel
If rebase fails (conflicts):
- Immediately abort rebase:
git -C "[worktree-path]" rebase --abort - Do NOT attempt to resolve conflicts
- Instruct user to resolve manually in worktree, then retry /worktree-end
- This keeps the worktree intact for manual conflict resolution
If worktree removal fails:
- Check if VS Code or other process has files open
- Suggest closing editors/terminals in that worktree
- Offer force removal as last resort
If branch deletion fails:
- If
-dfails (not fully merged): explain and offer-D - If remote deletion fails: show error, continue with local deletion
Safety Features
- Push before rebase: Branch is pushed to remote before any destructive operations
- Uncommitted changes check: Always check and prompt before proceeding
- Rebase abort on conflict: Immediately aborts rebase on conflict, preserves worktree
- Fast-forward only: Uses --ff-only to ensure clean linear history
- Explicit confirmation: Each destructive step has user confirmation
- Graceful failure: If any step fails, provide recovery options
- Main protection: Only merges INTO main via ff-only, never force-pushes main
Examples
Example 1: Clean Completion
User: "/worktree-end"
Skill Actions:
- Lists worktrees:
../feature-auth - User selects it
- Checks status - clean (no uncommitted changes)
- Pushes branch to remote - success
- Checks merge status - not merged
- Rebases branch onto main - success
- Fast-forward merges into main - success
- Pushes main to remote - success
- Removes worktree - success
- Asks about branch deletion - user selects "Delete local and remote"
- Deletes branch locally and on remote
- Shows summary (clean linear history)
Example 2: Has Uncommitted Changes
User: "/worktree-end feature-auth"
Skill Actions:
- Finds worktree:
../feature-auth - Checks status - HAS uncommitted changes:
M src/auth/mod.rs
- Asks user what to do
- User selects "Commit changes"
- Asks for commit message
- Commits changes
- Continues with push, merge, removal...
Example 3: Already Merged
User: "/worktree-end"
Skill Actions:
- Lists worktrees, user selects one
- Checks status - clean
- Pushes branch to remote
- Checks merge status - ALREADY merged
- Displays: "Branch is already merged to main. Skipping merge step."
- Removes worktree
- Asks about branch deletion
- Shows summary
Example 4: Rebase Conflict
User: "/worktree-end"
Skill Actions:
- Selects worktree
- Checks status - clean
- Pushes to remote - success
- Attempts rebase - CONFLICT
- Immediately aborts rebase:
git -C "../worktree" rebase --abort - Shows:
Rebase conflict detected. Aborting rebase. The worktree has NOT been modified. Please resolve this manually in the worktree: 1. cd ../feature-auth 2. git rebase main 3. Resolve conflicts 4. git rebase --continue 5. Run /worktree-end again - Skill stops (worktree preserved for manual resolution)
Comparison: worktree-end vs worktree-remove
| Feature | worktree-end | worktree-remove |
| Rebases onto main | Yes (clean history) | No |
| Merges to main | Yes (fast-forward) | No |
| Pushes to remote | Yes (safety) | No |
| Handles uncommitted changes | Prompts to commit | Warns only |
| Use case | Completing work | Abandoning/cleanup |
| Recommended for | Finished features | Experiments, already-merged |
Notes
- Always run from main repository, not from within a worktree
- Push happens BEFORE rebase for safety (branch preserved on remote)
- Rebase + fast-forward merge ensures clean linear history (no merge commits)
- If rebase conflicts, skill aborts and preserves worktree for manual resolution
- If anything fails, branch is safely on remote for recovery
- Branch deletion is optional and happens last
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

