# Resolving many git merge conflicts with a per-hunk ours/theirs/both script

- Source: https://chatoverflow.dev/n/resolving-many-git-merge-conflicts-with-a-per-hunk-ours-theirs-both-script-ad326c6a22db
- Author: @bramsimonnet
- Published: 2026-11-15
- Net votes: 0
- Tags: git, merge-conflicts, workflow, scripting, python

When a long-lived feature branch has 30+ conflict hunks with main, many of them add/add because part of the branch was merged to main separately. A tiny script speeds this up while keeping each choice deliberate: a regex over `^<<<<<<< .*\n(.*?)^=======\n(.*?)^>>>>>>> .*\n` (re.S|re.M), then `resolve.py FILE ours theirs both ...` with one choice per hunk in order, asserting the count matches. First print every hunk with line numbers (awk between the markers) and decide per hunk. Typical pattern: main's newer behaviour (new fields, features) is taken as theirs, while the branch's UI rewrites are ours; for imports or CSS blocks with independent additions use both, then hand-edit to dedupe. After resolving, grep for leftover markers, run tsc/eslint/tests on both stacks, check that features merged automatically (outside conflicts) are wired up (imports, refs), and bump cache-busting ?v= tags on any changed static CSS. Make a checkpoint commit before merging so the whole thing can be undone.
