GuidesUpdated

How do I resolve a merge conflict between two coding agents?

Find the conflicting branches, compare what each agent intended, make one integration decision, and test the combined behavior before review.

On this page

Worktrees stop two agents overwriting each other's files. They don't decide which behavior wins when both branches change the same code. Treat the conflict as a product decision: pause both agents, compare intent, resolve behavior, then test the combination.

Canopy Git diff view for inspecting competing changes
Canopy Git diff view for inspecting competing changes

Stop new edits and name one integrator

Pause both sessions at committed, reviewable states. Record each branch, worktree, issue and intended outcome. Pick one integrator and have a person approve the result; if agents keep writing, your decision goes stale. Canopy's Agent Workspace and Git views trace each session to its branch and diff.

Inspect both branches before you merge

In a clean integration checkout, run git status --short and diff both branches against their common base. Note the contract each expected. Say one agent renames a settings field while another validates the old name: Git may merge cleanly while the app breaks. Look for semantic overlap, not just marked conflicts.

Commit or preserve unrelated local work first. Git warns that aborting a merge may not restore uncommitted changes.

Resolve the behavior, then the text

Merge one reviewed branch, then the second. If Git stops, git status lists unmerged paths. Compare the markers and call sites with both branches and the base. Choose an outcome that meets both requirements, or send the decision back to the owners. Don't take ‘ours’ or ‘theirs’ for a whole file by habit; that silently discards valid work. Stage only resolved paths and read the staged diff before completing the merge.

Test the combination, not each branch alone

Run checks for both tasks plus one path that crosses them. For the renamed field, test a valid save, rejected input and the API payload in the running app. Each branch can pass alone and fail combined. Then scan the diff for leftover markers, missing code and API drift.

Record the decision and prevent the next collision

In the PR, list both branches, the conflicting contract, the chosen behavior, commands run and follow-ups. Tell both issue owners. Next time, agree shared interfaces early and give one owner files like routes, schemas and lockfiles. Worktrees protect directories; task boundaries protect the integration.

Copyable resources

Conflict triage commands

Run in a clean integration checkout; replace branch names and inspect before completing a merge.

git status --short
git branch --show-current
git diff --stat main...agent/first
git diff --stat main...agent/second
# Read each branch's brief and full diff first.
git merge agent/first
git merge agent/second
# If stopped on conflicts:
git status
git diff
# Resolve the required behavior, then stage only reviewed paths.
git add path/to/resolved-file
git diff --cached --check
git diff --cached
git merge --continue
# Run both task checks and an integration check before PR review.
# Unsure? Stop. git merge --abort may help, but check local changes first.

Frequently asked questions

Why did worktrees still produce a merge conflict?

Worktrees isolate working files while agents edit. Branches can still change the same lines or make incompatible assumptions when you combine them.

Can I ask an agent to take one side of every conflict?

Only after checking the other side has no required behavior. A whole-file choice can discard valid code without any visible error, so review both tasks and the final diff.

More questions and answers →

Sources and further reading