Topic 2 of 5 · 5 min read
Rebase, merge and agent conflict resolution
Goal: Resolve a conflict between two agent branches and verify that the merged result still contains both intended changes.
Rebase your own unpublished branch to keep history linear, merge anything others already use, and never accept a conflict resolution until you have checked that both sides' changes survived. Conflicts are normal when agents work in parallel. The risk is a resolution that quietly drops one side.
Check yourself · 1 of 3
When is it safe to rebase a branch?
Rebase or merge
- Rebase replays your commits on top of the new base. History is a straight line, but every replayed commit gets a new hash. Use it on branches only you have, such as an agent's task branch before review.
- Merge joins two histories with a merge commit and rewrites nothing. Use it for branches that others have pulled, and for integrating into main when your team wants the record of the branch.
The rule: never rebase commits that someone else may already have. If it is shared, merge.
Why agent conflict resolution needs a check
When Claude Code, Codex or Copilot resolves a conflict, it often picks the version that makes the build pass. That can mean deleting a block that "does not compile" but was the other agent's whole feature. The file compiles, the conflict markers are gone, and half the work has vanished.
How to do it
- Update the base:
git fetch origin. - Rebase one branch:
git rebase origin/main. Git stops at the first conflict. - Run
git diff --name-only --diff-filter=Uto list conflicted files, then read both sides. - Resolve, then
git add <file>andgit rebase --continue. To back out,git rebase --abort. - Verify both intents. Compare the result with each side:
git diff origin/main...agent/claude/login-fix # my branch's changes vs base
git diff ORIG_HEAD HEAD --stat # what the rebase changed
- Run the tests of both tasks, not only the one being rebased.
Before and after
Before: two branches both edit config.ts. One adds a retries option, the other adds a timeoutMs option. The agent's resolution keeps timeoutMs and drops retries. Tests for the first task now fail, but the agent reported "conflict resolved, build passes".
After: you diff the result against both branches, see retries missing, restore it, and run both test sets.
What goes wrong
- Rebasing a shared branch. Teammates get duplicate commits and a confusing history.
- Trusting "build passes". A missing feature does not always break the build.
- Taking one side whole.
git checkout --ourson a file discards the other side's work for that file. - Resolving repeatedly. A long branch hits the same conflict at every commit. Merge once, or rebase more often.
Examples
A resolution that dropped a side
- retries: 3,
timeoutMs: 5000,
The agent kept the incoming option and removed the existing one. The file is valid and the build is green. A diff against the first branch shows the removed retries line. The right resolution keeps both lines.
Which to use
Dana's agent branch agent/codex/csv-export has only her commits and no pull request yet: rebase it onto main. The release/2.4 branch has been pulled by three colleagues: merge main into it. Same command family, different safety rule.
Key points
- Rebase unpublished branches for a straight history; merge anything others may already have pulled.
- A conflict resolution that compiles can still delete the other agent's whole change.
- After resolving, diff the result against both parents and confirm each side's change is still present.
- Run the tests for both tasks, not only the branch being rebased.
- git rebase --abort and git reflog let you back out of a bad resolution.
Common mistakes
- Rebasing a branch that teammates or other agents have already pulled.
- Accepting an agent's resolution because the build passes, without diffing against both sides.
- Using --ours or --theirs on a whole file and losing the other side's changes.
- Skipping the tests for the other branch's feature after resolving.
Check yourself · 2 of 3
An agent says it resolved a merge conflict and the build passes. What is the best next step?
Check yourself · 3 of 3
You are partway through a rebase and the conflict is more tangled than expected. How do you return to the state before the rebase?
Practice items, not counted towards your mastery.
Start here
- Pro Git book (opens in a new tab)BookFree
The free reference book for branching, rebasing, reset and recovery, written by Git's maintainers' community.
- git-worktree documentation (opens in a new tab)DocsFree
How to give each task its own checkout of one repository, and how to list, lock and remove them.
- git-bisect documentation (opens in a new tab)DocsFree
Exact syntax for bisect start, good, bad, run and reset, with exit-code rules for scripts.
More for this topic
- git-rebase documentation (opens in a new tab)DocsFree
What rebase rewrites, how conflicts are reported, and the abort and continue commands.