🔀 Fix a Merge Driver Ignoring a .gitattributes Rule
A line like config/local.json merge=ours in .gitattributes only tells Git which named merge driver to use for that path — it doesn’t define the driver itself. The actual behavior has to be registered separately, typically in .git/config or a global config, under a [merge “ours”] section with a driver command. A fresh clone carries the .gitattributes file (it’s tracked and versioned like any other file) but never automatically carries that local or global config entry, so a new team member’s first merge on that file runs Git’s default recursive strategy instead of the custom one, with no warning that the referenced driver doesn’t actually exist on their machine.
🔎 The Problem
.gitattributes (tracked, present after every clone):
config/local.json merge=ours
.git/config (NOT tracked, missing on a fresh clone):
[merge "ours"]
driver = true
Result on a fresh clone: merge=ours is referenced but undefined locally,
Git silently falls back to the default merge strategy for that path,
producing ordinary conflict markers instead of the intended behavior
✅ Fix: A Merge Driver Ignoring a .gitattributes Rule
- Document the required merge driver setup as a one-time repo setup step (a script or a line in the README), since .gitattributes alone can never carry the driver definition across a clone.
- Check for the driver’s config entry explicitly after any fresh clone or new machine setup, with something like `git config –get merge.ours.driver`, before assuming a custom merge strategy is actually active.
- Where possible, replace a custom driver with a built-in Git merge strategy or attribute (such as the built-in `merge=union` or a documented `.gitattributes`-only option) that doesn’t require any separate local configuration at all.
🚨 Why This Is Dangerous
- A merge that silently falls back to the default strategy on a file meant to use “ours” or a custom resolution can quietly reintroduce conflict markers or unwanted changes into a file that every other clone’s config was protecting correctly.
gitattributes names the driver; it never ships the driver — and a fresh clone has no way to tell the two apart.





