Resolve Git Conflicts
Overview
Resolve Git conflicts end-to-end in the CLI. Analyze base/ours/theirs, decide which changes to keep or combine, verify the code works, then stop for human review before any commit or continue.
Quick Start
git status -sb
git diff --name-only --diff-filter=U
- For each file, inspect base/ours/theirs:
git show :1:PATH, git show :2:PATH, git show :3:PATH
- Edit files to a clean, marker-free result and run
git add PATH
- Run the repo build/tests if available
- Stop for review. Do not run
git commit, git merge --continue, git rebase --continue, or git cherry-pick --continue
Workflow
- Understand why the conflict happened.
Use
git status -sb and git log --oneline --decorate -n 20 to identify the operation and the competing commits.
- Analyze all versions.
Use
git show :1:PATH (base), :2: (ours), :3: (theirs). Use git diff --ours PATH and git diff --theirs PATH to see intent.
- Resolve conflicts with explicit choices.
Remove markers, choose
ours, theirs, or a combined result based on the decision framework. Prefer minimal, intention-preserving edits. Do not ask the user to edit; apply the changes directly and record the rationale in your response.
- Verify the code works.
Run the project's build/test/lint commands if defined. If none exist, run the smallest available smoke check.
- Handoff for review.
Stop after changes are staged and verified. Do not
git commit, git merge --continue, git rebase --continue, or git cherry-pick --continue. Provide a short summary of decisions and files touched for review.
Decision Framework
Do not default to ours or theirs. Decide per file using evidence.
Questions to answer before choosing:
- Which version matches the current API and usage sites?
- Which version aligns with the most recent refactor or commit intent?
- Which version is covered by or fixes failing tests?
- Which version removes deprecated code or references?
- Would combining both introduce duplication or inconsistent behavior?
Interpretation notes:
- In a merge,
ours is the current branch and theirs is the merged-in branch.
- In a rebase or cherry-pick,
ours is the branch you are applying onto and theirs is the commit being applied.
- If still ambiguous, choose the least risky change and state the assumption.
Commands
| Goal |
Command |
| List conflicted files |
git diff --name-only --diff-filter=U |
| See conflict markers |
`rg -n "<<<<<<< |
| Show base/ours/theirs |
git show :1:PATH, git show :2:PATH, git show :3:PATH |
| Diff ours vs file |
git diff --ours PATH |
| Diff theirs vs file |
git diff --theirs PATH |
| Accept ours/theirs quickly |
git checkout --ours PATH, git checkout --theirs PATH |
| Stage resolution |
git add PATH |
If rg is unavailable, use grep -n "<<<<<<<\\|======\\|>>>>>>>" PATH.
Example
Conflict:
function formatUser(user) {
<<<<<<< HEAD
return `${user.name} <${user.email}>`;
=======
return `${user.displayName} <${user.email}>`;
>>>>>>> feature/use-display-name
}
Resolved (use new field, keep fallback):
function formatUser(user) {
const name = user.displayName ?? user.name;
return `${name} <${user.email}>`;
}
Rationale: the feature branch introduced displayName, but existing callers may still populate name.
Common Mistakes
- Continuing a merge/rebase/cherry-pick before the review handoff.
- Treating
ours and theirs as fixed to "my branch" and "their branch" in all operations.
- Leaving conflict markers or partially resolved blocks in files.
- Auto-accepting one side without inspecting base and usage context.
1---2name: resolve-git-conflicts3description: Resolve Git conflicts from merge, rebase, cherry-pick, or stash operations.4---56# Resolve Git Conflicts78## Overview910Resolve Git conflicts end-to-end in the CLI. Analyze base/ours/theirs, decide which changes to keep or combine, verify the code works, then stop for human review before any commit or continue.1112## Quick Start13141. `git status -sb`152. `git diff --name-only --diff-filter=U`163. For each file, inspect base/ours/theirs: `git show :1:PATH`, `git show :2:PATH`, `git show :3:PATH`174. Edit files to a clean, marker-free result and run `git add PATH`185. Run the repo build/tests if available196. Stop for review. Do not run `git commit`, `git merge --continue`, `git rebase --continue`, or `git cherry-pick --continue`2021## Workflow22231. Understand why the conflict happened.24Use `git status -sb` and `git log --oneline --decorate -n 20` to identify the operation and the competing commits.252. Analyze all versions.26Use `git show :1:PATH` (base), `:2:` (ours), `:3:` (theirs). Use `git diff --ours PATH` and `git diff --theirs PATH` to see intent.273. Resolve conflicts with explicit choices.28Remove markers, choose `ours`, `theirs`, or a combined result based on the decision framework. Prefer minimal, intention-preserving edits. Do not ask the user to edit; apply the changes directly and record the rationale in your response.294. Verify the code works.30Run the project's build/test/lint commands if defined. If none exist, run the smallest available smoke check.315. Handoff for review.32Stop after changes are staged and verified. Do not `git commit`, `git merge --continue`, `git rebase --continue`, or `git cherry-pick --continue`. Provide a short summary of decisions and files touched for review.3334## Decision Framework3536Do not default to `ours` or `theirs`. Decide per file using evidence.37Questions to answer before choosing:38- Which version matches the current API and usage sites?39- Which version aligns with the most recent refactor or commit intent?40- Which version is covered by or fixes failing tests?41- Which version removes deprecated code or references?42- Would combining both introduce duplication or inconsistent behavior?4344Interpretation notes:45- In a merge, `ours` is the current branch and `theirs` is the merged-in branch.46- In a rebase or cherry-pick, `ours` is the branch you are applying onto and `theirs` is the commit being applied.47- If still ambiguous, choose the least risky change and state the assumption.4849## Commands5051| Goal | Command |52| --- | --- |53| List conflicted files | `git diff --name-only --diff-filter=U` |54| See conflict markers | `rg -n "<<<<<<<|======|>>>>>>>"` |55| Show base/ours/theirs | `git show :1:PATH`, `git show :2:PATH`, `git show :3:PATH` |56| Diff ours vs file | `git diff --ours PATH` |57| Diff theirs vs file | `git diff --theirs PATH` |58| Accept ours/theirs quickly | `git checkout --ours PATH`, `git checkout --theirs PATH` |59| Stage resolution | `git add PATH` |6061If `rg` is unavailable, use `grep -n "<<<<<<<\\|======\\|>>>>>>>" PATH`.6263## Example6465Conflict:66```javascript67function formatUser(user) {68<<<<<<< HEAD69 return `${user.name} <${user.email}>`;70=======71 return `${user.displayName} <${user.email}>`;72>>>>>>> feature/use-display-name73}74```7576Resolved (use new field, keep fallback):77```javascript78function formatUser(user) {79 const name = user.displayName ?? user.name;80 return `${name} <${user.email}>`;81}82```8384Rationale: the feature branch introduced `displayName`, but existing callers may still populate `name`.8586## Common Mistakes8788- Continuing a merge/rebase/cherry-pick before the review handoff.89- Treating `ours` and `theirs` as fixed to "my branch" and "their branch" in all operations.90- Leaving conflict markers or partially resolved blocks in files.91- Auto-accepting one side without inspecting base and usage context.