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¶
# .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¶
# 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 type | Driver | Command |
|---|---|---|
| npm/yarn/pnpm lockfiles | lockfile |
python3 scripts/merge-lockfile.py %O %A %B |
| JSON configs | jsoncfg |
python3 scripts/merge-json.py %O %A %B |
| Vendor blobs | theirs-wins |
cp %3 %2 |
| Gemfile.lock | union |
built-in |
Quick install all drivers¶
Verify in CI¶
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¶
git config --get-all --global merge.<name>.driver # list one driver
git config --get-regexp 'merge\..*\.driver' # list all drivers