Product case study · November 16, 2026

Claude Code: Resolve a Merge Conflict Without Losing a Feature

Build a small Git conflict, ask Claude Code to preserve both branches' requirements, and test the combined result before completing the merge.

Reading time
7 min
Checked
Nov 16, 2026
Blue and ochre paper branches converge on a cream card that preserves a distinct geometric shape from each branch
Keep both requirements when two branches collide.
Bottom line

A resolved conflict can still delete a feature. Give the agent both requirements and test their interaction before accepting the merge.

The quickest way to resolve a merge conflict is often to throw away somebody’s feature. Click “accept ours,” watch the red markers disappear, and you can end up with perfectly valid code that does less than either developer intended.

This exercise gives Claude Code a better job: combine two small requirements, then prove they work together. One branch makes a fictional command parser ignore capitalization. The other makes it ignore surrounding spaces. The finished parser needs both.

You need Bash, Git and Python 3. The optional agent step needs an installed, authenticated Claude Code. Sources checked November 16, 2026. The local Git fixture and Python checks were tested; an authenticated Claude session was not. The proposed resolution below is an authored reference, not a reported model response.

Create two changes worth keeping

Use one Bash terminal for the whole exercise. These commands create a fresh temporary repository, away from your real project. Do not enable set -e: the merge deliberately fails.

merge_lab=$(mktemp -d /tmp/claude-merge.XXXXXX)
cd "$merge_lab"
git init -q -b main
git config user.name 'Practice Author'
git config user.email 'practice@example.invalid'
git config commit.gpgsign false
git config core.hooksPath /dev/null
git config rerere.enabled false
git config merge.conflictStyle merge

printf 'def is_start(value):\n    return value == "start"\n' > command.py
git add command.py
git commit -qm 'Recognize the start command'
git switch -qc case-insensitive
printf 'def is_start(value):\n    return value.lower() == "start"\n' > command.py
git commit -qam 'Accept capitalized commands'

git switch -q main
printf 'def is_start(value):\n    return value.strip() == "start"\n' > command.py
git commit -qam 'Accept surrounding whitespace'
git merge --no-edit case-insensitive
git status --short

Expect a content conflict and UU command.py. Here, failure is the setup working: both branches changed the same line differently. If the merge succeeds or another error appears, inspect it before continuing; the remaining commands require an unresolved conflict.

Read all three versions

Before editing, inspect what each branch actually changed:

git show :1:command.py
git show :2:command.py
git show :3:command.py
cat command.py

The Git merge manual describes the three index stages for conflicting paths. In this ordinary merge, stage 1 is the common ancestor, stage 2 is the current HEAD, and stage 3 is the incoming branch. For this fixture:

VersionExpressionRequirement it covers
Ancestorvalue == "start"Exact matching only
Current branchvalue.strip() == "start"Surrounding whitespace
Incoming branchvalue.lower() == "start"Capitalization

Those labels describe this merge. Do not carry the same intuition into a rebase without checking its operation and version identities.

My preference is to make the requirements explicit before letting an agent touch the markers. Otherwise “resolve the conflict” can reasonably be interpreted as “choose a syntactically valid side.”

Give Claude a behavioral contract

Start claude in the practice directory; the CLI reference documents this interactive entry point. Paste:

Resolve only command.py in this disposable Git merge exercise.
First inspect the conflict and index stages 1, 2 and 3 for command.py.
Explain which requirement each branch added before editing.

The input contract is Python strings containing ASCII command words.
is_start must return a Boolean. Accept "start", "START", " start ",
and " START ". Reject "restart", "stop", and the empty string.
Preserve both case-insensitive matching and surrounding whitespace
trimming. Do not add substring matching or support new input types.

Edit only command.py. Do not stage, commit, abort the merge, switch
branches, or change tests or Git settings. Report the exact expression
you chose and any checks you actually ran. Stop after the edit.

Anthropic’s testing workflow recommends specifying the behavior to verify. The mixed case with spaces is the important example here: it exercises the interaction between the branches.

Review requested tool actions before approving them. The prompt defines the task scope; it is not a technical permission boundary. Exit Claude after the edit so you can inspect and test the file yourself.

A suitable reference resolution is:

def is_start(value):
    return value.strip().lower() == "start"

If you skip the model step, replace command.py with those two lines in your editor. This exercise deliberately limits the inputs; it is not a general Unicode command-normalization design.

Make either one-sided answer fail

Run this check from the practice repository before staging. It executes only the synthetic Python code you created:

python3 - <<'PY'
import runpy
import subprocess

cases = [
    ("start", True),
    ("START", True),
    (" start ", True),
    (" START ", True),
    ("restart", False),
    ("stop", False),
    ("", False),
]

for stage in (2, 3):
    source = subprocess.check_output(
        ["git", "show", f":{stage}:command.py"], text=True
    )
    namespace = {}
    exec(source, namespace)
    failures = [value for value, expected in cases
                if namespace["is_start"](value) is not expected]
    assert failures, f"Stage {stage} unexpectedly meets the whole contract"
    print(f"Stage {stage} misses: {failures!r}")

resolved = runpy.run_path("command.py")["is_start"]
for value, expected in cases:
    actual = resolved(value)
    assert actual is expected, (value, expected, actual)
print("PASS: resolved file meets all seven cases")
PY

Expect stage 2 to miss START and START, and stage 3 to miss start and START. The final line should report seven passing cases. Keeping either branch wholesale fails this check, even though it removes every conflict marker.

If Python reports a syntax error at a marker, the file is still unresolved. If only the mixed case fails, inspect whether the implementation actually combines both transformations. Do not weaken the test to match the chosen side.

Stage only after the behavior agrees

Once the Python check passes, inspect and stage the resolution:

git diff --check
git diff -- command.py
git add command.py
git diff --cached --check
git diff --cached -- command.py
git ls-files -u
git status --short

According to the Git diff reference, --check detects introduced conflict markers and whitespace errors. It does not test the parser’s behavior. Stop if either check reports a problem.

Expect git ls-files -u to print nothing after staging. That means no unresolved index entries remain; it does not mean your requirements passed. Also note that staging removes the three conflict stages, so the earlier comparison script belongs before git add.

For this disposable exercise, finish after reviewing the staged patch:

git commit -m 'Combine whitespace and capitalization support'
git log -1 --format='%s%nParents: %p'
git status --short

Expect the merge commit to have two parent hashes and the working tree to be clean. Nothing is pushed.

To abandon the exercise before committing, use git merge --abort while the merge is still in progress. It discards this attempted resolution. In a real repository, preserve existing work before starting: Git documents that abort cannot always reconstruct pre-merge uncommitted changes.

The useful review question is now concrete: which requirement from each branch survives, and what input proves they work together? Ask that before celebrating the disappearance of the markers.

Sources checked November 16, 2026

Put this to work

Distinguish removing conflict markers from preserving the intent of a merge.

Try

Combine case-insensitive matching and whitespace trimming in one Python function.

Prove it worked

Show that either branch alone fails the combined contract, while the resolved function passes.

Keep in view

  • Create a disposable merge conflict with two legitimate changes.
  • Compare the ancestor and both branch versions before asking Claude to edit.
  • Test the combined behavior before staging and committing the resolution.
Learn the workflow: Define acceptance checks before accepting AI code