Skill: git-conflict-resolver
Purpose
Autonomously handle most git merge conflicts by understanding the semantic intent of the conflicting code changes.
When to Use
- •When
git merge mainorgit rebase mainfails with conflicts. - •As a pre-flight check before starting work on a long-running feature branch.
How It Works
This skill delegates conflict resolution to a MergeConflict Sub-Agent.
Step 1: Attempt the Merge
bash
git fetch origin main git merge origin/main
If this succeeds, no further action is needed.
Step 2: If Conflicts Occur, Invoke the Sub-Agent
bash
# Get list of conflicted files CONFLICTED_FILES=$(git diff --name-only --diff-filter=U) # For each conflicted file, invoke the sub-agent for FILE in $CONFLICTED_FILES; do claude --print "You are a MergeConflict sub-agent. Your task is to resolve the merge conflict in the following file. **File:** $FILE **Conflict Markers:** $(cat $FILE) **Your Task:** 1. Understand the intent of the changes on BOTH sides of the conflict. 2. Determine the correct resolution that preserves the intent of both changes. 3. Output the resolved file content WITHOUT any conflict markers. **Rules:** - Do NOT simply choose one side. Merge the logic if possible. - If the conflict is too complex to resolve automatically, output 'ESCALATE' and explain why. " done
Step 3: Apply the Resolution
If the sub-agent outputs resolved code:
- •Write the resolved content to the file.
- •Run
git add $FILE. - •Run the verification gates (lint, test) to ensure the resolution is correct.
- •If verification passes, run
git commit -m "chore: resolve merge conflict in $FILE".
Step 4: Escalate Complex Conflicts
If the sub-agent outputs ESCALATE:
- •Log the conflict to
progress.txt:markdown## [Date] - Merge Conflict Escalation - **File**: src/services/UserService.ts - **Reason**: Conflicting refactors on both branches. Cannot determine correct merge without human input.
- •Mark the current story as
blocked-merge. - •Run
git merge --abortto restore the branch to a clean state. - •Move on to the next story.
Configuration
Add the following to your CLAUDE.md:
markdown
## Git Conflict Resolution - **Strategy**: merge (or rebase) - **Auto-Resolve**: Enabled for simple conflicts. - **Escalation Threshold**: Conflicts involving more than 50 lines or structural changes.