Core Purpose
Perform branch merges safely and resolve conflicts only with explicit user authorization.
Manual Invocation Gate
Proceed only when the user has explicitly invoked $manual-merge-branches or clearly directed the agent to use this skill in the current conversation.
If this condition is not met, stop and do not run merge/conflict commands under this skill.
Required Entry Conditions
Accept exactly one of these starting conditions:
- Active merge conflict state already exists.
- User provides one branch to merge into the current branch.
- User provides a source branch and a target branch.
If none applies, ask the user for missing branch input before running merge commands.
Optional Pre-Step
Use branch-context when recent branch history is needed to:
- understand the intent behind the branches being merged, or
- make safer conflict-resolution suggestions in an existing merge state.
Workflow
- Detect current state.
- Choose one entry path from the required conditions.
- Synchronize required branches with remote (
fetch, thenpull --ff-onlywhen possible). - Run merge.
- If conflicts occur, run the conflict resolution protocol.
Path 1: Already In Merge Conflict State
- Confirm merge state (
git statusand unresolved files). - Do not start a new merge.
- Move directly to the conflict resolution protocol.
Path 2: Merge One Provided Branch Into Current Branch
- Record current branch as target branch.
- Validate source branch exists (local or remote).
- Synchronize source branch:
git fetch --all --prune- If source branch can be checked out safely, checkout source and run
git pull --ff-only, then return to target. - If checkout/pull is not possible, fetch source and merge from
origin/<source>as fallback.
- Run merge from target branch.
Path 3: Merge Source Branch Into Named Target Branch
- Validate both branch names exist (local or remote).
- Ensure workspace is safe for branch switching.
- Synchronize both branches:
git fetch --all --prune- Checkout source and run
git pull --ff-onlywhen possible. - Checkout target and run
git pull --ff-onlywhen possible. - If either pull is not possible, use fetched remote refs (
origin/<branch>) as fallback.
- From target branch, run merge using source.
Conflict Resolution Protocol
When merge conflicts exist:
- Enumerate conflicts with
git diff --name-only --diff-filter=U. - Process each conflicted file individually.
- For each file, inspect conflict hunks and produce a suggested resolution that includes:
- what to keep from
ours, - what to keep from
theirs, - any combined/manual rewrite needed,
- brief rationale and risk note.
- what to keep from
- Request explicit approval before applying each suggestion.
- Accept either:
- per-conflict approvals, or
- blanket approval (for example: "resolve all conflicts yourself").
- Apply only approved resolutions. It is valid to resolve a subset and leave others pending.
- After each approved change:
- stage resolved file(s),
- report remaining conflicted files.
- Continue until all conflicts are resolved or user stops.
Approval Guardrail
Never apply a conflict resolution without explicit approval coverage for that change.
Completion
After conflicts are resolved:
- Confirm no unresolved conflicts remain.
- Show concise merge summary (
git statusand resolved files). - Ask user before any final commit/push action unless already explicitly requested.