worktree-resolve
Skill19 starsChanged 3 months agoMITView on GitHub
Resolve and merge git worktrees after swarm completion
In this repository25 other files it gives its agents.
- assess-findingsSkill
- autopilotSkill
- build-fixSkill
- code-searchSkill
- context-usageSkill
- debugSkill
- decideSkill
- designSkill
- docsSkill
- forgetSkill
- gitSkill
- implementSkill
- memoriseSkill
- patternsSkill
- perfSkill
- plan-swarmSkill
- recallSkill
- reflectSkill
- reviewSkill
- semgrepSkill
- surveySkill
- swarmSkill
- swarm-statusSkill
- testSkill
- verifySkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 7 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 25
Check the AIDE worktree state file for metadata and status:
- Very specific: line 61
Run these steps for every feat/* branch from swarm:
- Distinctive: line 94
If conflicts shown, note them for manual resolution.
- Very specific: line 107
When merge conflicts occur, do not use -X theirs or -X ours - these blindly discard changes.
- Distinctive: line 109
Instead, resolve conflicts intelligently:
- Very specific: line 146
Remove all conflict markers (<<<<<<<, =======, >>>>>>>)
- Distinctive: line 166
If you cannot resolve the conflict (logic is contradictory, tests fail after resolution, or changes are too complex):
- Very specific: line 188
Use -X theirs or -X ours to blindly pick one side
- Distinctive: line 226
After all branches merged:
- Distinctive: line 302
Continue with remaining branches: - do not block on one failure
- Distinctive: line 356
Keep backups: - create a tag before bulk operations: git tag pre-swarm-merge
- Very specific: line 357
Don't force delete: - use -d not -D to prevent deleting unmerged work
- Distinctive: line 358
Report all failures: - never silently skip branches
≈ “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 Resolution
Recommended model tier: balanced (sonnet) - this skill performs straightforward operations
Merge all swarm worktrees back into the main branch after testing.
Workflow
1. List Active Worktrees
git worktree listCheck the AIDE worktree state file for metadata and status:
cat .aide/state/worktrees.jsonWorktree Status Values:
active- Agent is still working on this worktreeagent-complete- Agent finished, ready for merge reviewmerged- Successfully merged to main
Only merge worktrees with status agent-complete.
Example state file:
{
"active": [
{
"name": "story-auth",
"path": ".aide/worktrees/story-auth",
"branch": "feat/story-auth",
"taskId": "story-auth",
"agentId": "agent-auth",
"status": "agent-complete",
"createdAt": "2026-02-07T...",
"completedAt": "2026-02-07T..."
}
],
"baseBranch": "main"
}2. For Each Worktree Branch
Run these steps for every feat/* branch from swarm:
a) Test the Branch
# Checkout the worktree
cd .aide/worktrees/<name>
# Run tests
npm test # or appropriate test command
# Run linting
npm run lint # or appropriate lint command
# Check build
npm run build # if applicableb) Review Changes
# Back in main repo
git log main..feat/<name> --oneline
git diff main...feat/<name> --statc) Check Merge Compatibility
# Dry-run merge check
git merge-tree $(git merge-base main feat/<name>) main feat/<name>If conflicts shown, note them for manual resolution.
3. Merge Clean Branches
For branches that pass tests and have no conflicts:
git checkout main
git merge feat/<branch-name> --no-edit4. Handle Conflicts (Intelligent Resolution)
When merge conflicts occur, do not use -X theirs or -X ours - these blindly discard changes.
Instead, resolve conflicts intelligently:
Step 1: Attempt merge and identify conflicts
git merge feat/<name> --no-edit
# If conflicts occur, git will list the conflicted filesStep 2: For each conflicted file, read and analyze
# Read the file with conflict markers
cat <conflicted-file>The conflict markers show:
<<<<<<< HEAD
[changes from main branch]
=======
[changes from feature branch]
>>>>>>> feat/<name>Step 3: Resolve as a code review expert
Act as an expert code reviewer. For each conflict:
- Analyze both code paths - What was each change trying to achieve?
- Understand the intent - Are they complementary, overlapping, or contradictory?
- Modify the feature branch locally to incorporate main's changes while preserving the feature's logic
- Edit the file to remove conflict markers and combine both sets of functionality correctly
The resolution must:
- Remove all conflict markers (
<<<<<<<,=======,>>>>>>>) - Preserve the functional intent of BOTH changes
- Be syntactically and semantically correct
- Maintain code style consistency
Step 4: Verify and complete
# Stage the resolved files
git add <resolved-file>
# Run tests to verify the resolution works
npm test # or appropriate test command
# If tests pass, complete the merge
git commit --no-editStep 5: Handle failure
If you cannot resolve the conflict (logic is contradictory, tests fail after resolution, or changes are too complex):
Abort the merge to restore clean state:
git merge --abort- Record the failure using aide messaging:
./.aide/bin/aide message send --from=resolver --to=orchestrator "CONFLICT: Cannot merge feat/<name> - <brief reason>"
Binary location: The aide binary is at .aide/bin/aide. If it's on your $PATH, you can use aide directly.
- Skip this branch and continue with remaining branches
- Report at completion - list unmerged branches in the final summary for manual review
Do NOT:
- Force through a broken resolution
- Use
-X theirsor-X oursto blindly pick one side - Get stuck - always abort and report if resolution fails
Example Resolution
Conflict:
<<<<<<< HEAD
function getUser(id: string): User {
return db.users.find(u => u.id === id);
}
=======
function getUser(id: string): User | null {
const user = db.users.find(u => u.id === id);
return user ?? null;
}
>>>>>>> feat/null-safetyAnalysis:
- HEAD: Basic lookup returning User
- Feature: Added null-safety with explicit null return
Resolution:
function getUser(id: string): User | null {
const user = db.users.find((u) => u.id === id);
return user ?? null;
}Feature branch improved null safety - this is additive, keep it.
5. Cleanup
After all branches merged:
# Remove each worktree
git worktree remove .aide/worktrees/<name>
# Delete merged branches
git branch -d feat/<name>
# Prune any orphaned worktrees
git worktree prune
# Clear state file
rm .aide/state/worktrees.json6. Final Verification
# Ensure all tests pass on main
git checkout main
npm test
npm run lint
npm run build
# Check no worktrees remain
git worktree list # Should only show mainSummary Report
After resolution, report:
## Worktree Resolution Complete
### Merged Branches
- feat/task1-agent1: ✓ (3 files, +150/-20)
- feat/task2-agent2: ✓ (5 files, +280/-45)
### Skipped (conflicts/failures)
- feat/task3-agent3: Test failures in auth.test.ts
### Final Status
- All tests passing: ✓
- Lint clean: ✓
- Build successful: ✓Quick Commands
# List all feat branches from swarm
git branch --list 'feat/*'
# Merge all clean branches at once (risky - prefer one at a time)
for branch in $(git branch --list 'feat/*' | tr -d ' '); do
git merge $branch --no-edit || echo "Conflict in $branch"
done
# Bulk cleanup worktrees
git worktree list | grep '.aide/worktrees' | awk '{print $1}' | xargs -I {} git worktree remove {}
# Bulk delete feat branches (only if merged)
git branch --list 'feat/*' | xargs git branch -dFailure Handling
If merge fails:
- Abort immediately:
git merge --abort - Record the failure:
./.aide/bin/aide message send --from=resolver --to=orchestrator "Merge failed: feat/<name> - <reason>" - Continue with remaining branches - do not block on one failure
- Include in final report - list all failed branches with reasons
If tests fail after merge:
- Revert the merge:
git revert -m 1 HEAD - Record the failure with aide messaging
- Continue with other branches
If worktree removal fails:
# Force remove if necessary
git worktree remove --force .aide/worktrees/<name>
# Prune any orphaned entries
git worktree pruneVerification Criteria
After each merge:
# Verify merge commit exists
git log -1 --oneline
# Verify no uncommitted changes
git status --porcelain # Should be empty
# Verify tests pass
npm test # or appropriate test commandAfter full resolution:
# Verify all worktrees removed
git worktree list # Should only show main worktree
# Verify all feature branches deleted (or list unmerged)
git branch --list 'feat/*' # Should be empty for merged branches
# Verify main is clean
git status
# Verify final tests pass
npm test && npm run lint && npm run buildSafety Notes
- Always test each branch before merging
- Merge one at a time to isolate issues
- Keep backups - create a tag before bulk operations:
git tag pre-swarm-merge - Don't force delete - use
-dnot-Dto prevent deleting unmerged work - Report all failures - never silently skip branches
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.

