Skip to content

Merge Driver Quick Reference ​

Core concepts ​

Every merge driver receives three args: $O (base), $A (ours / output), $B (theirs). Driver writes resolved output to $A. Exit 0 = success, 1 = conflict (Git marks conflict markers).

Built-in drivers ​

bash
# .gitattributes
*.lock   merge=union   # concatenate both sides (dedup harmless for additive files)
*.pbxproj merge=union
*.gitignore merge=union
*.png   merge=binary   # always prefer ours (no meaningful merge for binaries)

Register a custom driver ​

bash
# 1. Define in global config
git config --global merge.<name>.name "Human-readable description"
git config --global merge.<name>.driver "<command> %O %A %B"

# 2. Reference in .gitattributes
echo "package-lock.json  merge=<name>" >> .gitattributes

Common DevOps drivers ​

File typeDriverCommand
npm/yarn/pnpm lockfileslockfilepython3 scripts/merge-lockfile.py %O %A %B
JSON configsjsoncfgpython3 scripts/merge-json.py %O %A %B
Vendor blobstheirs-winscp %3 %2
Gemfile.lockunionbuilt-in

Quick install all drivers ​

bash
bash scripts/install-merge-drivers.sh

Verify in CI ​

bash
git merge --no-commit --no-ff origin/feature-branch
# Check for unresolved conflicts in managed file types
if git ls-files -u | grep -q '\.lock$'; then echo "UNRESOLVED LOCKFILE CONFLICTS"; exit 1; fi

Show registered drivers ​

bash
git config --get-all --global merge.<name>.driver   # list one driver
git config --get-regexp 'merge\..*\.driver'        # list all drivers

Unset a driver ​

bash
git config --global --unset merge.<name>.driver
git config --global --unset merge.<name>.name
# Then remove the line from .gitattributes

Git Master — Git Reference for Every Skill Level