| name | merge-conflict-resolver |
| description | Analyze branch divergence, detect potential conflicts, and guide merge resolution for any Git repository. Auto-detects current branch or accepts parameters. |
| tags | ["git","merge","conflict-resolution","devops"] |
| version | 1.0.0 |
| author | DevOps Agent (Clay) |
Merge Conflict Resolver Skill
Overview
A comprehensive skill for analyzing Git branch divergence, detecting potential merge conflicts before they occur, and guiding users through systematic conflict resolution. This skill provides both automated analysis and manual resolution workflows.
Features
1. Intelligent Auto-Detection
- Detects current branch automatically if not specified
- Auto-discovers repository root using
git rev-parse --show-toplevel
- Defaults to
origin/main as target branch (configurable)
- Works in any Git repository without hardcoded paths
2. 8-Step Analysis Workflow
- Branch Verification - Validates current branch state
- Status Display - Shows recent commits and current HEAD
- Fetch Latest - Updates remote branch information
- Commit Comparison - Analyzes branch divergence (merge-base analysis)
- Change Analysis - Shows commits unique to each branch
- File Changes - Lists modified files in both branches
- Conflict Detection - Identifies files changed in both branches (potential conflicts)
- Merge Attempt - Attempts automatic merge with detailed reporting
3. Color-Coded Output
- RED - Errors and conflict detection
- GREEN - Success messages and confirmations
- YELLOW - Warnings and important information
- BLUE - Section headers and step markers
4. Multiple Resolution Strategies
- Automated -
resolve-merge-conflicts.sh (orchestrator)
- Detailed Analysis -
analyze-and-merge.sh (8-step workflow with guidance)
- Simple Merge -
simple-merge.sh (basic merge helper)
- Status Check -
check-merge-status.sh (non-destructive analysis)
Usage
Quick Start (Recommended)
cd /path/to/your/repo
/path/to/skills/merge-conflict-resolver/scripts/resolve-merge-conflicts.sh
./scripts/resolve-merge-conflicts.sh feature/my-branch origin/main
./scripts/resolve-merge-conflicts.sh feature/my-branch
Detailed Analysis
./scripts/analyze-and-merge.sh feature/my-branch origin/main
./scripts/analyze-and-merge.sh
Status Check Only
./scripts/check-merge-status.sh
Simple Merge Helper
./scripts/simple-merge.sh feature/my-branch origin/main
When to Use This Skill
Perfect For:
- ✅ Resolving merge conflicts in feature branches
- ✅ Pre-merge analysis to detect potential conflicts
- ✅ Understanding branch divergence before creating PRs
- ✅ Teaching merge conflict resolution workflows
- ✅ Automated merge workflows in CI/CD pipelines
- ✅ Multi-developer teams with frequent branch conflicts
Not Suitable For:
- ❌ Automated conflict resolution (requires human judgment)
- ❌ Rebasing workflows (use
git rebase instead)
- ❌ Interactive conflict resolution (use
git mergetool)
- ❌ Cherry-picking specific commits (use
git cherry-pick)
Output Examples
Success Case (No Conflicts)
==================================================================
✓ SUCCESS: Merge completed without conflicts!
==================================================================
New HEAD:
abc1234 Merge origin/main into feature/my-branch
def5678 Latest feature commit
...
Next steps:
1. Review the merge: git log --oneline -10
2. Push to remote: git push origin feature/my-branch
Conflict Case (Manual Resolution Needed)
=================================================
✗ MERGE CONFLICTS DETECTED
=================================================
Conflicting files:
UU src/main.py
UU config/settings.json
⚠ Files changed in both branches:
src/main.py
config/settings.json
Resolution steps:
1. Review conflicts in the files listed above
2. Edit each file to resolve conflicts (look for <<<<<<< markers)
3. git add <resolved-file>
4. Repeat for all files
5. git merge --continue
Or to abort:
git merge --abort
Pre-Merge Analysis
[Step 7] Checking for potential conflicts...
✓ No overlapping file changes detected
Merge should be clean!
Files changed in our branch:
src/feature.py
tests/test_feature.py
Files changed in origin/main:
src/unrelated.py
docs/README.md
Configuration
Environment Variables
export DEFAULT_TARGET_BRANCH="origin/develop"
export NO_COLOR=1
export AUTO_ABORT_ON_CONFLICT=1
Script Parameters
All scripts accept optional parameters:
./scripts/resolve-merge-conflicts.sh [source-branch] [target-branch]
Parameter Defaults:
source-branch: $(git branch --show-current) (current branch)
target-branch: origin/main (or $DEFAULT_TARGET_BRANCH)
Error Handling
Common Errors
Not in a Git repository:
ERROR: Not in a Git repository
Run this script from inside a Git repository
Branch doesn't exist:
ERROR: Branch 'feature/nonexistent' not found
Available branches: git branch -a
Already up to date:
✓ Already up to date with origin/main
No merge needed.
Dirty working directory:
ERROR: Working directory has uncommitted changes
Commit or stash changes before merging:
git stash
git commit -am "Save work"
Rollback and Recovery
Abort Merge in Progress
git merge --abort
Reset to Before Merge
git reset --hard ORIG_HEAD
git reset --hard origin/feature/my-branch
Preserve Work Before Resetting
git stash
git reset --hard origin/feature/my-branch
git stash pop
Integration Examples
CI/CD Pipeline (GitHub Actions)
name: Check Merge Conflicts
on:
pull_request:
branches: [main]
jobs:
check-merge:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check for conflicts
run: |
./skills/merge-conflict-resolver/scripts/check-merge-status.sh
- name: Analyze merge
run: |
export NO_COLOR=1 # Disable colors in CI logs
./skills/merge-conflict-resolver/scripts/analyze-and-merge.sh
continue-on-error: true
Pre-Merge Hook
#!/bin/bash
/path/to/skills/merge-conflict-resolver/scripts/check-merge-status.sh
if [ $? -ne 0 ]; then
echo "Merge conflict detected. Resolve before committing."
exit 1
fi
Automated Merge Script
#!/bin/bash
set -euo pipefail
FEATURE_BRANCH="$1"
TARGET_BRANCH="${2:-origin/main}"
if ! ./skills/merge-conflict-resolver/scripts/analyze-and-merge.sh "$FEATURE_BRANCH" "$TARGET_BRANCH"; then
echo "Automatic merge failed - manual intervention required"
exit 1
fi
git push origin "$FEATURE_BRANCH"
Troubleshooting
Merge Failed with Many Conflicts
Try rebase instead:
git merge --abort
git rebase origin/main
git add <resolved-file>
git rebase --continue
Lost Changes After Merge
git reflog
git reset --hard HEAD@{N}
Scripts Not Executable
chmod +x skills/merge-conflict-resolver/scripts/*.sh
Best Practices
Before Merging
- ✅ Always fetch first:
git fetch origin
- ✅ Check branch status: Run
check-merge-status.sh
- ✅ Analyze potential conflicts: Run
analyze-and-merge.sh first
- ✅ Commit or stash changes: Clean working directory before merge
- ✅ Review recent commits: Understand what you're merging
During Conflict Resolution
- ✅ Read conflict markers carefully:
<<<<<<<, =======, >>>>>>>
- ✅ Test after each resolution: Don't resolve all at once
- ✅ Keep both changes when possible: Merge functionality, don't just delete
- ✅ Preserve security fixes: Don't accidentally revert critical changes
- ✅ Document complex resolutions: Add comments explaining why
After Merging
- ✅ Review the merge commit:
git show HEAD
- ✅ Run tests: Ensure nothing broke
- ✅ Check for unintended changes:
git diff HEAD~1
- ✅ Update documentation: Note conflicts resolved
- ✅ Push promptly: Don't leave resolved merges unpushed
File Structure
skills/merge-conflict-resolver/
├── SKILL.md # This file
├── README.md # Usage guide
└── scripts/
├── resolve-merge-conflicts.sh # Main orchestrator
├── analyze-and-merge.sh # Detailed 8-step analysis
├── simple-merge.sh # Basic merge helper
└── check-merge-status.sh # Status checker
Contributing
Adding Features
- Keep auto-detection logic in all scripts
- Maintain color-coded output conventions
- Provide clear error messages with actionable steps
- Test with multiple Git repository types
- Update both SKILL.md and README.md
Testing
cd /tmp
git init test-repo
cd test-repo
git remote add origin <test-repo-url>
/path/to/scripts/check-merge-status.sh
/path/to/scripts/analyze-and-merge.sh feature/test origin/main
Version History
- v1.0.0 (2025-11-17) - Initial release
- 8-step analysis workflow
- Auto-detection of branches and repository
- Color-coded output
- Multiple resolution strategies
- Comprehensive error handling
License
MIT License - Use freely in any Git workflow
Support
For issues or questions:
- Check this documentation first
- Review example outputs in README.md
- Examine script comments for implementation details
- Test in a safe repository before production use
Remember: Merge conflict resolution requires human judgment. These scripts analyze and guide, but you make the final decisions about which changes to keep.