You're working on a team project and need to keep personal configuration files (like CLAUDE.md or .claude/) that may also exist in the remote repository. The challenge: how do you prevent git pull from overwriting your local versions? Traditional solutions like .gitignore or .git/info/exclude don't work here—they only affect untracked files. If the file exists in the remote repo, Git will try to sync it during pulls.
Git's custom merge drivers let you define how specific files should be merged. We can create a driver that always keeps your local version.
Step 1: Configure the Merge Driver
Run this command in your repository:
git config merge.ours.driver true
This creates a merge driver named "ours" that does nothing (returns true), effectively keeping your local version unchanged.
Note: Without any flags, this config is local to your repository only—it won't affect other projects or other developers.
Step 2: Specify Which Files Use This Driver
Create or edit .git/info/attributes:
CLAUDE.md merge=ours
.claude/* merge=ours
This tells Git: "For these files, use the 'ours' merge driver during merge operations."
How It Works
When you git pull:
To avoid accidentally committing your local configuration, add these files to .git/info/exclude
:
CLAUDE.md
.claude
This prevents them from being staged with git add. Combined with the merge driver, you're fully protected—both from remote overwrites (merge driver) and accidental commits (exclude).