Analyze branch divergence, detect potential conflicts, and guide merge resolution for any Git repository. Auto-detects current branch or accepts parameters.
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.
git rev-parse --show-toplevelorigin/main as target branch (configurable)resolve-merge-conflicts.sh (orchestrator)analyze-and-merge.sh (8-step workflow with guidance)simple-merge.sh (basic merge helper)check-merge-status.sh (non-destructive analysis)# Auto-detect current branch, merge from origin/main
cd /path/to/your/repo
/path/to/skills/merge-conflict-resolver/scripts/resolve-merge-conflicts.sh
# Specify branches explicitly
./scripts/resolve-merge-conflicts.sh feature/my-branch origin/main
# Or just specify source branch
./scripts/resolve-merge-conflicts.sh feature/my-branch
# Run comprehensive 8-step analysis before merging
./scripts/analyze-and-merge.sh feature/my-branch origin/main
# Auto-detect branches
./scripts/analyze-and-merge.sh
# Check current state without making any changes
./scripts/check-merge-status.sh
# Basic merge workflow (less verbose)
./scripts/simple-merge.sh feature/my-branch origin/main
git rebase instead)git mergetool)git cherry-pick)==================================================================
ā 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
=================================================
ā 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
[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
# Override default target branch
export DEFAULT_TARGET_BRANCH="origin/develop"
# Disable color output (for CI/CD logs)
export NO_COLOR=1
# Auto-abort on conflicts (for automation)
export AUTO_ABORT_ON_CONFLICT=1
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)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"
# Cancel merge and return to pre-merge state
git merge --abort
# Reset to previous state (ORIG_HEAD)
git reset --hard ORIG_HEAD
# Or reset to remote branch
git reset --hard origin/feature/my-branch
# Save current work
git stash
# Reset to clean state
git reset --hard origin/feature/my-branch
# Restore work
git stash pop
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 # Full history for merge-base
- 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 # Allow conflicts
#!/bin/bash
# .git/hooks/pre-merge-commit
# Run conflict analysis before allowing merge
/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
#!/bin/bash
# automated-merge.sh
set -euo pipefail
FEATURE_BRANCH="$1"
TARGET_BRANCH="${2:-origin/main}"
# Check for conflicts first
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
# Push if successful
git push origin "$FEATURE_BRANCH"
Try rebase instead:
git merge --abort
git rebase origin/main
# Resolve conflicts one commit at a time
git add <resolved-file>
git rebase --continue
# Check reflog for lost commits
git reflog
# Restore from reflog
git reset --hard HEAD@{N} # Replace N with appropriate index
# Make scripts executable
chmod +x skills/merge-conflict-resolver/scripts/*.sh
git fetch origincheck-merge-status.shanalyze-and-merge.sh first<<<<<<<, =======, >>>>>>>git show HEADgit diff HEAD~1skills/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
# Test in various scenarios
cd /tmp
git init test-repo
cd test-repo
git remote add origin <test-repo-url>
# Test auto-detection
/path/to/scripts/check-merge-status.sh
# Test with parameters
/path/to/scripts/analyze-and-merge.sh feature/test origin/main
MIT License - Use freely in any Git workflow
For issues or questions:
Remember: Merge conflict resolution requires human judgment. These scripts analyze and guide, but you make the final decisions about which changes to keep.