DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowHalloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
FREEDOM251

Freedom251 › Blog › coding agents

How to Fix Merge Conflicts and Duplicated Edits After Using Multiple Coding Agents

By Freedom251 Team · · 10 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not choose “ours” or “theirs” automatically. First preserve the repository state, identify every agent’s intended behavior, then resolve the conflict into one tested result. A safe sequence is: run git status, inspect the conflicting paths and three versions of each file, edit the combined result, remove every conflict marker, review the diff, stage it with git add, and finish with git merge --continue or a merge commit. If two agents implemented the same feature without a textual conflict, compare both diffs against their common starting point and consolidate the behavior deliberately.

What a merge conflict is—and what it is not

A Git merge conflict is a warning that Git cannot safely decide which change should win. The common case is two branches changing the same line, but conflicts also occur when one side edits a file that the other side deletes. Git has stopped before creating the merge commit so you can decide what the final code should do.

As an Amazon Associate I earn from qualifying purchases.

The conflict is not proof that one agent is correct and the other is wrong. In a multi-agent workflow, both edits may contain useful parts, or one may reflect a newer interface that the other agent did not know about. Treat the markers as a request to inspect intent, not as a vote for one side.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A second problem is different: duplicated edits. Two agents can implement the same behavior in different files or in different commits, and Git may merge those changes cleanly because the lines do not overlap. The result can compile while containing duplicate functions, repeated migrations, two competing API calls, or tests that exercise only one implementation. This requires semantic consolidation, not just marker removal.

Stabilize the repository before editing

  1. Stop additional merges and agent writes. Ask every agent to pause in the affected repository or worktree. Continuing to edit while you diagnose makes the working tree harder to reason about.
  2. Record the current state. Run
    git status

    Git lists unmerged paths and tells you whether a merge is in progress. Save the output in your task notes if several agents are involved.

  3. Check for unrelated local work. A merge can include edits that were already present before it started. Do not overwrite those changes while resolving a conflict; identify their owner and keep them separate from the merge decision.
  4. Inspect the merge direction. Establish which branch is the current side and which branch is being merged in. The labels “ours” and “theirs” are relative to that operation, not permanent names for particular agents.

If the worktree contains valuable uncommitted edits that are unrelated to the merge, stop and preserve them before proceeding. The exact preservation method depends on your team’s policy; the important rule is that you must know which changes belong to which task before staging anything.

Resolve a normal textual conflict step by step

1. Read the markers in context

Open each unmerged file and locate the markers:

<<<<<<< HEAD
current-side code
=======
incoming-side code
>>>>>>> feature-branch

The marker text is only a view of a three-way decision. Read the surrounding function, its callers, and nearby tests. Determine what each agent was trying to accomplish rather than comparing isolated lines.

2. Inspect base, current, and incoming versions

While a textual merge is unresolved, Git keeps three index stages for the path:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Stage Meaning Useful command
1 Base version shared before the two branches diverged git show :1:path/to/file
2 Current branch, also called “ours” for this merge git show :2:path/to/file
3 Incoming branch, also called “theirs” for this merge git show :3:path/to/file

Replace path/to/file with the repository-relative path. You can also compare the working result with each side using Git’s conflict diff views:

git diff --base -- path/to/file
git diff --ours -- path/to/file
git diff --theirs -- path/to/file

The base version answers “what did both agents start from?” The current and incoming versions show which behavior each branch added or changed. This is especially important when a marker block is small but the surrounding function was refactored differently by both agents.

3. Write the intended combined result

Edit the file so it expresses one coherent design. Sometimes that means retaining one side; often it means combining validation from one change with the data flow from the other. Update imports, function signatures, error handling, comments, and tests as needed. Do not leave conflict markers in comments or strings: search the entire file for <<<<<<<, =======, and >>>>>>> after editing.

When the agents changed an interface, inspect every call site. A conflict can be syntactically resolved while callers still pass the old arguments or expect the old return value. Compile or run the narrowest relevant test before moving on, then run the project’s normal checks after all paths are staged.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Review before staging

Use the diff to inspect what you are about to record:

git diff -- path/to/file
git diff

Where the merge strategy supports it, git diff AUTO_MERGE can show the merge result against the automatically generated state. Review for accidental deletions, duplicated imports, changed formatting that hides a logic error, and code copied from the wrong side.

5. Mark the file resolved

Once the file contains the desired result, stage it:

git add path/to/file

Run git status again. The path should no longer appear under unmerged files. Repeat the inspect-edit-review-stage cycle for every conflicted path; staging one file does not resolve the others.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

6. Finish the merge

If Git reports that the merge can continue, run:

git merge --continue

If your setup does not provide a continuation step, create the merge commit with:

git commit

Git opens the merge-message editor unless your configuration supplies a message. After the merge completes, inspect the final commit and run the project’s tests. A clean status only means the index is resolved; it does not prove that the combined behavior is correct.

Handle conflict types that markers do not explain

Not every conflict can be solved by editing the text between markers. Git’s lower-level merge behavior distinguishes several cases.

Conflict What happened Decision you must make
Edit/edit Both sides changed overlapping content. Keep, combine, or redesign the behavior after comparing all three versions.
Edit/delete One side edited a path while the other deleted it. Decide whether the feature still needs the file. If it does, retain and adapt it; otherwise remove it and update references.
Rename-related Both branches renamed or changed a path in incompatible ways. Choose the canonical path, preserve required content, and fix imports, build rules, and references.
Binary file Git cannot merge the file as line-oriented text. Select a complete version or regenerate the artifact from source. Do not paste binary marker text into it.
File/directory One side uses a path as a file while the other uses it as a directory, or vice versa. Choose the intended layout and move or delete paths consciously.

For these cases, inspect the index and the branch trees rather than assuming that the visible marker block tells the whole story. Check generated files and build metadata after a rename or deletion; stale references are a common post-merge failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Do not use “ours” or “theirs” as a blind repair

Git supports options such as -Xours, -Xtheirs, and the ours merge strategy. They are not interchangeable, and they are not generic conflict-fix buttons. The -Xours and -Xtheirs options favor one side in conflicting hunks, while the ours strategy can record a merge that discards the other tree’s content entirely. Either choice can silently remove an agent’s useful work.

Use one-sided resolution only when you have verified that the discarded change is intentionally obsolete. If you need one side for a particular file, make that decision explicitly, inspect the resulting diff, and still run tests. Never apply a repository-wide preference merely because the conflict list is long.

Find and remove duplicated implementations

A clean merge can still contain duplicate work. This happens when two agents implement the same requirement in non-overlapping locations, or when one agent copies a new helper while another adds an equivalent helper under a different name.

Compare both changes with the common starting point

  1. Identify the common base commit from which the agents started.
  2. Review each branch’s diff against that base, not only the final combined tree.
  3. Group changes by behavior: API endpoints, database migrations, background jobs, UI handlers, validation, and tests.
  4. Trace call sites and configuration to see which implementation is actually reachable.

The goal is to compare intent and side effects. Two functions that look similar may differ in authorization, transaction boundaries, error handling, or performance. Conversely, a duplicate may be the same behavior exposed through two names, in which case retaining both creates maintenance risk.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose a canonical implementation

Select the implementation that fits the project’s existing interfaces and tests, then move any necessary behavior from the other branch into it. Remove redundant code, imports, registrations, migrations, and feature flags. Update every caller and add or adjust tests so the consolidated path is exercised. Do not leave both versions “temporarily” unless there is an explicit compatibility period with an owner and removal date.

Check data and operational side effects

Duplicates are especially dangerous when code runs once per request or deployment. Look for repeated event subscriptions, two scheduled jobs, migrations that create the same object, duplicate routes, or two clients writing the same record. Run integration tests and inspect startup logs or registration tables where the project provides them.

Abort a merge that should not proceed

If the merge direction was wrong or the combined result cannot be trusted, Git documents:

git merge --abort

This attempts to return the worktree to the state before the merge began. Changes made while resolving the merge, or changes that were already present and not cleanly recorded before the merge, may require separate cleanup. After aborting, run git status and verify that valuable local work is still present before trying another integration plan.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the duplicate implementation is already committed, first determine whether the commit is local-only or has been shared or published. The safe history-repair method depends on that answer and on your team’s branch policy. Coordinate before rewriting shared history; do not treat reset or rebase commands as universally safe. For a published branch, a forward corrective commit is often easier for collaborators to consume, but the repository’s release and review rules decide the final procedure.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Prevent collisions when delegating to multiple agents

Give each agent a narrow, testable contract

Write down the task, expected result, files the agent owns, files it must not touch, interfaces it may change, generated files, and the checks it must run. Separate independent work whenever possible. OpenAI’s multi-agent guidance states: “Agents that edit the same files must coordinate their changes.” If overlap is deliberate, agree on the integration order and the shared contract before editing begins.

Coordinate shared interfaces before implementation

Most painful conflicts are not about formatting; they are about incompatible assumptions. Before agents code, agree on function signatures, schema fields, route names, error formats, feature flags, and ownership of migrations. Have one agent land the contract first when practical, then let other agents build against that stable interface.

Use one worktree per agent when available

Git worktrees provide separate working directories associated with one repository. An agent can edit and test in its own directory without overwriting another agent’s uncommitted files. OpenAI’s Codex app description likewise describes isolated copies for parallel agents.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Approach Isolation of uncommitted edits Repository-state sharing Integration overhead
Separate worktrees High: each agent has its own working directory. Shared repository objects and selected references, with separate checked-out files. Requires explicit branch/worktree management and a final merge or cherry-pick.
One shared directory Low: agents can overwrite or stage one another’s files. Immediate visibility, but ownership is easy to lose. Less setup, much higher coordination burden; agents editing the same files must communicate continuously.

Worktrees reduce direct workspace collisions; they do not guarantee conflict-free integration. Two isolated agents can still change the same behavior, interface, or lines, so their branches must be reviewed and merged.

Make integration a reviewable queue

  1. Ask each agent to commit only its scoped task and report changed files, assumptions, and tests.
  2. Review the diff against the task before integrating it.
  3. Merge or apply one logical change at a time so a conflict has a small search space.
  4. Run the project’s checks after each integration boundary, not only at the end.
  5. Record follow-up work when an agent discovers a shared file or contract that needs coordination.

This process catches semantic duplication even when Git reports no textual conflict.

Use a visual merge tool when it improves review

Git supports external tools through git mergetool. A three-pane view can make the base, current side, incoming side, and result easier to compare than raw markers, especially for long functions or multiple conflict hunks. Git’s documentation gives KDiff3 as an example of such a tool, but capabilities, platform support, and pricing vary by tool and version.

Choose a visual tool when it provides:

  • a clear base/ours/theirs/result layout;
  • support for the repository’s conflict types, including renames where applicable;
  • an easy way to inspect the final file rather than merely select panes;
  • availability on every contributor’s platform; and
  • a review trail that still allows the team to inspect the resulting Git diff.

A tool accelerates comparison; it does not determine product intent. After saving a tool’s result, run git diff, stage manually, and test as you would after a command-line resolution.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Final verification checklist

  • State: git status shows no unmerged paths and only expected changes.
  • Markers: no conflict markers remain in source, configuration, documentation, or generated text.
  • Behavior: the final code reflects the requirements of both tasks, or records why one change was intentionally rejected.
  • Interfaces: callers, schemas, routes, imports, and configuration agree with the merged signatures.
  • Duplicates: equivalent helpers, registrations, migrations, jobs, and tests have been consolidated or explicitly versioned.
  • Diff: the staged and final diffs contain no accidental deletions or unrelated formatting churn.
  • Tests: focused tests pass first, followed by the project’s normal build, lint, and integration checks.
  • History: collaborators know whether the result is a new merge commit, an abort followed by another attempt, or a corrective commit for an already shared change.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

coding agentsdeveloper workflowGitmerge conflictsVersion Controlworktrees

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.