Resolve a Git Merge Conflict and Keep What Both Branches Intended

Paste your conflict markers and get a plain explanation of each side's change, a merged version that keeps both intents, and a test checklist.

You getSide A, side B and merged code

Prompt

Prompt
Act as a senior software engineer who reviews merge conflicts for a team.

I will paste one or more git conflict blocks right after this message. They will include the lines between the conflict markers and, when I can, a few lines of surrounding code and the two branch names. Resolve the conflict.

Rules:
1. Before proposing anything, describe what each side changed in plain words and quote the exact lines that differ.
2. State the likely intent behind each change with a confidence level (high, medium, low). Do not guess silently.
3. The merged version must keep both intents unless they truly contradict. If they do, say which one you kept and why.
4. Return complete code with no conflict markers left, in the original language, indentation and naming style.
5. If the snippet is too short to judge (missing imports, callers or tests), name the exact lines or files you need instead of guessing.

Output format:
1. Side A (ours / HEAD): what changed, likely intent, confidence
2. Side B (theirs / incoming): what changed, likely intent, confidence
3. Merged code: one code block
4. Why this merge: 2-4 bullets
5. Test before committing: numbered checklist of specific cases, commands or files to check

End with one line naming any assumption you made or the main risk this merge carries.

Example output

At a glanceWhat each branch changed in fetch_invoiceThe merged version keeps both intents: bounded attempts that retry.
ItemSide A (main)Side B (feature/retry)
ChangeAdds timeout=10 to client.getRetry loop with retries=3
IntentStop slow calls hanging workersRecover from brief upstream errors
Error handlingNone addedraise_for_status, logs, InvoiceFetchError
ConfidenceHighHigh

Example for: a Python billing service where main added a request timeout and feature/retry added retries with logging to the same function.

1. Side A (ours / HEAD, main)

Changed def fetch_invoice(client, invoice_id): to accept timeout=10 and passes timeout=timeout to client.get.
Intent: stop slow invoice calls from hanging workers. Confidence: high.

2. Side B (theirs / incoming, feature/retry)

Wrapped the call in a loop with retries=3, added raise_for_status(), logs each failure with logger.warning, and raises InvoiceFetchError after the last attempt.
Intent: recover from brief upstream errors. Confidence: high.

3. Merged code
def fetch_invoice(client, invoice_id, timeout=10, retries=3):
    for attempt in range(1, retries + 1):
        try:
            response = client.get("/invoices/" + invoice_id, timeout=timeout)
            response.raise_for_status()
            return response.json()
        except (requests.HTTPError, requests.Timeout) as err:
            logger.warning(
                "Invoice %s fetch failed (attempt %d of %d): %s",
                invoice_id, attempt, retries, err,
            )
    raise InvoiceFetchError(invoice_id)
4. Why this merge
  • Both parameters are kept with their original defaults, so existing callers on either branch still work.
  • The timeout is applied inside the retry loop, so each attempt is bounded.
  • requests.Timeout is added to the caught errors; otherwise A's timeout would bypass B's retries and crash on the first slow response.
  • Worst-case wait is now about 30 seconds (3 x 10). If that is too long for the worker, lower retries or timeout.
5. Test before committing
  1. Run git diff --check and grep -n "<<<<<<<" billing/invoices.py to confirm no markers remain.
  2. Unit test: a mock client that times out twice then succeeds returns the invoice and logs 2 warnings.
  3. Unit test: a client that always returns 503 raises InvoiceFetchError after exactly 3 calls.
  4. Search callers with grep -rn "fetch_invoice(" . and check none pass positional arguments that now shift.
  5. Run the full suite: pytest tests/billing -q.
  6. Confirm requests is imported in this file on the merged result.

Assumption: retrying on timeouts is safe because fetch_invoice is a read-only GET; do not copy this pattern to non-idempotent calls.

Written by AI from this prompt. Your results will vary.

Tips and common edits

Why this works

  • Explaining each side before merging forces the model to understand intent instead of just picking one block of lines.
  • Confidence levels and the rule to ask for missing lines reduce confident but wrong merges on partial snippets.
  • A concrete test checklist with commands catches leftover markers and behavior clashes before the commit lands.

Use when git stops a merge or rebase with conflicts. Copy the full conflict block plus a few surrounding lines and the branch names, then paste it into ChatGPT, Claude or Gemini after the prompt.

Common edits

  • Paste several conflict blocks at once and ask for one section per file.
  • Add your team's rule, such as 'prefer main when in doubt', to rule 3.

Prompt details

By
Prompts-GPT editors
Published

Did this prompt work?

Keep exploring

More in Coding