Analyze and resolve Git merge/rebase conflicts intelligently, showing diffs and asking clarifying questions when needed. Invoke with /resolve-conflicts.
64
81%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
Passed
No findings from the security scan
You are tasked with helping resolve Git merge or rebase conflicts. This command handles both active conflict states and proactive conflict preview/resolution.
First, determine the current state:
# Check if we're in the middle of a merge
git rev-parse --verify MERGE_HEAD 2>/dev/null && echo "MERGE_IN_PROGRESS" || echo "NO_MERGE"
# Check if we're in the middle of a rebase
test -d "$(git rev-parse --git-dir)/rebase-merge" -o -d "$(git rev-parse --git-dir)/rebase-apply" && echo "REBASE_IN_PROGRESS" || echo "NO_REBASE"
# Check for unmerged files (active conflicts)
git diff --name-only --diff-filter=UBased on results:
# Current branch
git branch --show-current
# Target branch (default: main)
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@' || echo "main"
# Fetch latest to ensure accurate comparison
git fetch origin# List all conflicted files AND capture the list now — once files are staged
# in Step 5, `--diff-filter=U` returns nothing. Step 7's merge commit message
# reads this file.
git diff --name-only --diff-filter=U | tee /tmp/conflicted.txt
# Show the conflict markers in each file
git diff --check# Show what would change when merging target into current
git diff origin/main...HEAD --name-status
# Show detailed diff
git diff origin/main...HEAD --stat
# Identify files modified in both branches (potential conflicts)
git log origin/main..HEAD --name-only --pretty=format: | sort -u > /tmp/head_files
git log HEAD..origin/main --name-only --pretty=format: | sort -u > /tmp/main_files
comm -12 /tmp/head_files /tmp/main_filesFor each conflicted or potentially conflicting file:
# For active conflicts - show the three-way diff
git diff <file>
# Show "ours" version (current branch)
git show :2:<file>
# Show "theirs" version (incoming branch)
git show :3:<file>
# Show common ancestor
git show :1:<file>For each file, analyze:
For each conflict, suggest one of:
When intent is ambiguous, ask specific questions:
For overlapping edits:
"In
<file>at line X, both branches modified the same code:
- Current branch: [summary of change]
- Incoming branch: [summary of change]
Which behavior should we keep?
- Current branch's approach
- Incoming branch's approach
- Combine both (explain how)
- Need more context to decide"
For structural conflicts:
"The file
<file>was restructured differently in both branches:
- Current branch: [describe restructure]
- Incoming branch: [describe restructure]
This requires manual review. Would you like me to show the full diff?"
For semantic conflicts:
"Both branches changed the logic in
<function>:
- Current: [behavior description]
- Incoming: [behavior description]
These may be incompatible. Which business logic is correct?"
After understanding all conflicts and getting answers to questions:
git checkout --ours <file>
git add <file>git checkout --theirs <file>
git add <file>Edit the file to combine both changes, then:
git add <file>After editing:
# Verify no conflict markers remain
grep -n "^<<<<<<< " <file> && echo "Still has conflict markers!" || git add <file>After resolving all conflicts:
# Check no unmerged files remain
git diff --name-only --diff-filter=U
# Verify no conflict markers in staged files
git diff --cached | grep -E "^[+](<<<<<<<|=======|>>>>>>>)" && echo "Warning: Conflict markers still present!"
# Show what will be committed
git diff --cached --stat# Commit the merge, citing the conflicted-file list captured in Step 2.
# Do NOT use `git diff --name-only HEAD~1` here — that lists every merged
# file, not just the files whose conflicts were resolved.
git commit -m "Merge origin/main into $(git branch --show-current)
Resolved conflicts in:
$(cat /tmp/conflicted.txt)"# Continue the rebase
git rebase --continueIf more conflicts appear during rebase, repeat from Step 3.
After completion, provide:
| File | Resolution Type | Notes |
|---|---|---|
path/to/file1.ts | Accept Theirs | Our changes were outdated |
path/to/file2.ts | Merge Both | Combined feature additions |
path/to/file3.ts | Manual | Required semantic understanding |
If resolution isn't going well:
git merge --abortgit rebase --abort39b3f44
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.