Appearance
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>" >> .gitattributesCommon 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
bash
bash scripts/install-merge-drivers.shVerify 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; fiShow registered drivers
bash
git config --get-all --global merge.<name>.driver # list one driver
git config --get-regexp 'merge\..*\.driver' # list all driversUnset a driver
bash
git config --global --unset merge.<name>.driver
git config --global --unset merge.<name>.name
# Then remove the line from .gitattributes