| name | git-conflict-resolution |
| description | Reference material for resolving git merge and rebase conflicts. Covers conflict marker anatomy, resolution strategies by file type, context gathering, and rules for correct resolution. |
Git Conflict Resolution
Reference for the resolve-conflicts session command. Covers how to read, understand, and resolve git conflicts correctly.
Conflict Marker Anatomy
A conflict block in a file looks like this:
<<<<<<< HEAD
// Code from the current branch (ours)
const timeout = 5000;
=======
// Code from the incoming branch (theirs)
const timeout = 10000;
>>>>>>> feature-branch
| Marker | Meaning |
|---|
<<<<<<< HEAD | Start of the current branch's version (ours) |
======= | Separator between the two versions |
>>>>>>> {ref} | End of the incoming branch's version (theirs) |
During a merge: "ours" is the branch you're on, "theirs" is the branch being merged in.
During a rebase: "ours" is the branch you're rebasing onto, "theirs" is the commit being replayed (your branch's changes). This is the reverse of merge — your own changes appear as "theirs."
Resolution Strategies by File Type
Code Files
- Read
git log for both refs to understand the intent behind each side's changes
- Read surrounding code (imports, related functions, tests) for semantic context
- Merge the logic from both sides — do not blindly pick one side
- If one side is a strict superset of the other (e.g., one side added a feature, the other made a small fix), take the superset and apply the fix
- If both sides modified the same function differently, understand what each change achieves and write a version that incorporates both intents
- Verify the resolved code compiles logically (matching braces, correct imports, no duplicated declarations)
Lock Files
Lock files (package-lock.json, pnpm-lock.yaml, yarn.lock) cannot be meaningfully merged:
- Delete the conflicted lock file
- Run the appropriate package manager to regenerate:
npm install for package-lock.json
pnpm install for pnpm-lock.yaml
yarn install for yarn.lock
- Stage the regenerated file
Generated Files
Files that are generated by tooling (compiled output, auto-generated code, bundled assets):
- Delete the conflicted file
- Run the generation command
- Stage the result
Config Files
Configuration files (tsconfig.json, .eslintrc, docker-compose.yml, etc.):
- Compare both versions structurally
- Prefer the more complete version — the one with more entries or newer settings
- If both sides added different entries, include all entries from both sides
- Validate JSON/YAML syntax after resolution
Context Gathering
Before resolving, gather context to make informed decisions:
- Git log:
git log --oneline -10 {base_ref} and git log --oneline -10 {incoming_ref} — understand what each branch was doing
- Related files: read files imported by or related to the conflicted file
- Project conventions: check CLAUDE.md and .claude/rules/ for project-specific patterns
- Tests: check if either side added tests that reveal the intended behavior
Rules
- Never leave conflict markers — every
<<<<<<<, =======, >>>>>>> must be removed
- Resolve all conflicts in one pass — do not leave any files partially resolved
- Stage immediately —
git add each file right after writing the resolution
- Lock files: always regenerate — never attempt to merge lock file contents
- Fail on true ambiguity — if both sides make valid but contradictory changes and there is no way to determine the correct resolution from context, report failure rather than guess
- Do not commit — the caller (merge/rebase function) handles the commit or rebase continuation
- Verify with
git diff --check — confirm no conflict markers remain after resolution