Protecting Local Configuration Files from Git Remote Overwrites

git

The Problem

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.

The Solution: Custom Merge Driver

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:

  1. Git detects changes to CLAUDE.md from remote
  2. Sees the file is configured with merge=ours driver
  3. Runs the driver (which does nothing: true)
  4. Keeps your local version, ignores remote changes

Prevent Accidental Commits

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).