Index of every page on this site: llms.txt
All skills
stealth-factory avatar

/resolve-merge-conflicts

@802887c
Run it yourself

Resolve git merge/rebase conflicts non-destructively — preserving the intent of BOTH sides — and hand off to a human when a conflict can't be resolved safely. Use when a branch or PR has conflicts with its base ('this branch has conflicts that must be resolved', GitHub mergeable=CONFLICTING / mergeStateStatus=DIRTY), when a rebase / merge / cherry-pick / stash / revert stops with conflict markers (<<<<<<< ======= >>>>>>>), when a PR is behind base and needs updating, when syncing a long-lived branch or back-merging a hotfix, or when deciding rebase vs merge. Covers the safe-resolution rules (no blind -X ours/theirs, hunk-by-hunk with diff3, abort/reflog escape hatches, verify-after), the rebase ours/theirs inversion, lockfile/rename/semantic conflicts, and the escalate-when-stuck criteria.

Use this Skill: https://skilld.dev/gh/stealth-factory/skills/resolve-merge-conflicts

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referenceplaybook.md

≈1.5k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Conflict-resolution playbook

The git/gh recipes for the loop in ../SKILL.md. Read this when you need the exact commands; the decision rules live in the SKILL.

0. Turn on the aids (once, safe to keep global)

# Show the common ancestor in conflict hunks — the single biggest aid: you see what
# EACH side changed FROM, instead of guessing. zdiff3 (Git ≥ 2.35) also de-dupes
# common lines; fall back to diff3 on older Git.
git config --global merge.conflictStyle zdiff3   # or: diff3 on Git < 2.35 (check `git --version`)

# Reuse Recorded Resolution: remember how you resolved a hunk and auto-apply it if
# the SAME conflict recurs (e.g. replaying many commits in a rebase).
git config --global rerere.enabled true

1. Understand — what's conflicting and why

# Is a PR actually conflicting (vs just behind)? `mergeable` is the coarse signal
# (MERGEABLE / CONFLICTING / UNKNOWN); `mergeStateStatus` is finer: DIRTY = conflicts,
# BEHIND = just needs an update (no conflicts). Note: CLEAN is a mergeStateStatus value,
# NOT a mergeable value.
gh pr view <PR> --repo <owner/name> --json mergeable,mergeStateStatus,baseRefName,headRefName

# Bring the base in. Pick ONE of:
git fetch origin
git rebase origin/main      # linear history; you'll force-with-lease after
#   …or…
git merge  origin/main      # one resolution pass; normal push after

# Once stopped at a conflict:
git status                  # lists "both modified", "deleted by us/them", etc.
git diff                    # the conflict hunks (with diff3/zdiff3 context)
git diff --name-only --diff-filter=U   # just the unmerged paths

Rebase ours/theirs is inverted. Mid-rebase, --ours = the branch you're replaying onto (e.g. main), --theirs = your commits being replayed. Mid-merge it's the intuitive way round (ours = your branch). The index stage slots are fixed (:1 = common ancestor/base, :2 = "ours", :3 = "theirs") — but because the labels flip, mid-rebase :2 holds the upstream/main content and :3 holds YOUR commit. Inspect a side explicitly before acting on it: git show :1:<file> (base) · git show :2:<file> (ours — = main during a rebase) · git show :3:<file> (theirs — = your commit during a rebase).

2. Resolve — hunk by hunk

  • Open each unmerged file; for every <<<<<<< / ======= / >>>>>>> block, write the line(s) that preserve both intents (use the ||||||| base block from diff3 to see what each side changed). Delete all three markers.

  • Mark resolved: git add <file>.

  • Wholesale-one-side is allowed ONLY when correct, not to silence markers:

    git checkout --theirs path/to/regenerated-file && git add path/to/regenerated-file

Lockfiles — regenerate, don't hand-merge

# Take either side to clear the conflict, then rebuild the lock from the (already
# resolved) manifest so it's internally consistent. (Which side --theirs points at
# flips mid-rebase — see the ours/theirs inversion note above — but regeneration
# makes the choice irrelevant for the lock-only modes below.)
git checkout --theirs package-lock.json && npm install --package-lock-only   # npm (lock only)
git checkout --theirs pnpm-lock.yaml   && pnpm install --lockfile-only   # pnpm
git checkout --theirs yarn.lock        && yarn install            # yarn (classic)
git add <the-lockfile>

3. Verify — before continuing

git diff --check && git diff --cached --check   # leftover markers + whitespace (working AND staged)
# Belt-and-braces full-tree scan (incl. diff3's |||||||). Scan ALL tracked files —
# do NOT exclude *.md: a real conflict hides in READMEs/docs too.
! git grep -nE '^(<{7}|\|{7}|={7}|>{7})( |$)'
# build + tests here — the ONLY thing that catches a semantic conflict
# (textually clean, logically broken). e.g.: npm run build && npm test

4. Continue & push

# Merge:
git commit                           # default message records the resolution
git push

# Rebase:
git rebase --continue                # repeat resolve→add→continue per replayed commit
git range-diff origin/main @{u} HEAD   # sanity (base old new): only YOUR changes remain
                                     #   (@{u} needs an upstream set + a prior push)
git push --force-with-lease          # NEVER plain --force on a shared branch
                                     #   (a background/IDE auto-fetch can defeat the lease)

Abort & recover (the escape hatch)

git merge  --abort        # back to clean pre-merge state
git rebase --abort        # back to clean pre-rebase state
git cherry-pick --abort
git rebase --skip         # DROPS the current commit entirely — only when it became a no-op (already upstream)

# Recover after a bad finish:
git reflog                # find the pre-op SHA
git reset --hard ORIG_HEAD          # undo the just-completed merge/rebase
git reset --hard <sha-from-reflog>  # or jump to any prior state

Escalation (fork / untrusted PR)

A PR from a fork has an attacker-controlled checkout and a read-only token — don't check it out and run its code. You usually can't push the fix to its branch either (a 403), unless maintainerCanModify is true. Confirm and hand off:

gh pr view <PR> --repo <owner/name> --json isCrossRepository,headRepositoryOwner,maintainerCanModify
# isCrossRepository true (or a different headRepositoryOwner) → fork. If maintainerCanModify
# is false you can't push the fix either → ask the contributor to rebase, or resolve
# via the GitHub web conflict editor under a human's account.

When handing off any conflict, post the facts and leave a clean tree:

git merge --abort 2>/dev/null || git rebase --abort 2>/dev/null   # don't leave a half-state
gh pr comment <PR> --repo <owner/name> --body "$(cat <<'EOF'
Conflicts with base in: <files>. Tried <rebase/merge>; <which hunks> need an author
decision (both sides changed <X> deliberately). Stopping here — needs a human call.
EOF
)"

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts3mo3 checks · Risk SAFE
  • Gen Agent Trust Hub3mo

    This skill provides a set of best practices and command recipes for resolving git merge and rebase conflicts. It prioritizes data integrity and human oversight, particularly when handling untrusted code or complex logic clashes. The tool usage is standard for development environments, and no malicious patterns were detected.

  • Socket3mo

    No alerts

  • Snyk3mo

    Risk: LOW · No issues

Signed by skilld at 802887c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated 3 months ago
Other metadata
metadata
{
  "author": "stealth-factory",
  "co-author": "wiiiimm",
  "version": "1.1.0"
}

README badge

README badge for stealth-factory/skills/resolve-merge-conflicts