meganide

merge

0
0
# Install this skill:
npx skills add meganide/claude --skill "merge"

Install specific skill from multi-skill repository

# Description

Fetch latest from origin main and merge with the current branch. Handles conflicts interactively by presenting changes and recommendations.

# SKILL.md


name: merge
description: Fetch latest from origin main and merge with the current branch. Handles conflicts interactively by presenting changes and recommendations.
allowed-tools: Bash(git fetch:), Bash(git merge:), Bash(git status:), Bash(git diff:), Bash(git log:), Bash(git checkout:), Bash(git add:), Bash(git branch:)


Merge - Sync with Origin Main

This skill fetches the latest changes from origin main and merges them into your current branch.

Context

  • Current branch: !git branch --show-current
  • Git status: !git status --short
  • Recent commits on current branch: !git log --oneline -5

Instructions

Step 1: Fetch Latest from Origin

git fetch origin main

Step 2: Attempt Merge

Run the merge command:

git merge origin/main

Step 3: Handle Result

If merge succeeds without conflicts:
- Report success with a summary of what was merged
- Show any new commits that were brought in: git log --oneline HEAD@{1}..HEAD

If merge has conflicts:

  1. Get the list of conflicted files:
    bash git status --porcelain | grep "^UU\|^AA\|^DD\|^AU\|^UA\|^DU\|^UD"

  2. For EACH conflicted file, analyze the conflict:

  3. Read the file to see the conflict markers
  4. Use git diff --base <file> to see what changed
  5. Use git log --oneline -3 origin/main -- <file> to understand incoming changes
  6. Use git log --oneline -3 HEAD -- <file> to understand local changes

  7. Present each conflict to the user using AskUserQuestion with:

  8. Question: Clear description of the conflict in this file
  9. Header: The filename (shortened if needed)
  10. Options (provide 2-4 relevant options based on the conflict):
    • Keep ours: Description of what "our" version contains
    • Keep theirs: Description of what "their" (origin/main) version contains
    • Keep both: Combine both changes (only if this makes sense for the conflict)

Include your recommendation by putting "(Recommended)" at the end of the option you think is best based on:
- Which change is more complete
- Which change is newer/more relevant
- Whether one change encompasses the other

  1. After user selects resolution for each file:
  2. Apply the chosen resolution
  3. Stage the resolved file: git add <file>

  4. After ALL conflicts are resolved:

  5. Complete the merge: git commit --no-edit
  6. Report success

Example Conflict Question

For a conflict in src/utils/helpers.ts:

Question: "Conflict in helpers.ts: Local branch adds a 'formatDate' function, while origin/main adds 'parseDate' function in the same location. Which version should we keep?"
Header: "helpers.ts"
Options:
- Label: "Keep ours (Recommended)"
  Description: "Keep local 'formatDate' function - appears to be new feature work"
- Label: "Keep theirs"
  Description: "Keep origin/main 'parseDate' function"
- Label: "Keep both"
  Description: "Include both functions - they don't conflict logically"

Handling Specific Conflict Types

For code conflicts:
- Analyze what each side changed
- Recommend based on which change is more complete or logical

For package.json/lock file conflicts:
- Usually recommend keeping theirs and re-running install
- Mention if local has dependencies that need to be re-added

For configuration files:
- Carefully analyze what each change does
- Often recommend keeping both changes merged manually

For deleted vs modified conflicts:
- Check if the deletion was intentional
- Recommend based on whether the file should exist

Important Notes

  • NEVER force push or use destructive git commands
  • NEVER skip conflict resolution
  • Always explain what's happening at each step
  • If something goes wrong, report the error and suggest how to recover
  • If user wants to abort the merge, run git merge --abort

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.