Stop .DS_Store files appearing on external drives
If you're a developer, .DS_Store is the file that shows up in git status, sneaks into a pull request, or litters the external SSD you keep your repos on. macOS writes it into every folder Finder opens. You can stop it on external drives with a single setting — and stop it reaching your repositories at all with a global gitignore. Here's both halves, because they solve different parts of the same annoyance.
Stop it on external drives
For folders on a USB or external drive, one defaults key does it — there's no System Settings toggle:
# Stop .DS_Store on USB / external drives
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true
# Undo
defaults write com.apple.desktopservices DSDontWriteUSBStores -bool false
The change applies after you log out and back in (or restart). If you also keep code on a network share or NAS, set the sibling key DSDontWriteNetworkStores the same way. Both work on macOS 13 Ventura, 14 Sonoma, and 15 Sequoia.
The catch: repos on your internal drive
Here's the part worth being precise about. DSDontWriteUSBStores only governs USB and removable volumes — it does nothing for folders on your Mac's internal disk, and there's no supported key to stop .DS_Store there. So if the .DS_Store that keeps landing in your commits comes from a repo in ~/Projects, this setting won't touch it. Finder will keep creating the file whenever you open the folder — you just want git to ignore it.
Keep it out of every repo with a global gitignore
The right fix for repositories is a global ignore, set once, that applies to all of them:
# Create a global gitignore and register it
echo ".DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
From now on git ignores .DS_Store in every repo on the machine, whether the code sits on the internal drive or an external one. If a file is already tracked in a project, remove it from the index once:
# Stop tracking a .DS_Store that already got committed
git rm --cached .DS_Store
git commit -m "Remove .DS_Store from repo"
Clean the drive you already have
Neither setting removes files that already exist. Clear an external drive or a project tree with find:
# Delete existing .DS_Store under a folder or mounted drive
find /Volumes/DEV_SSD -name .DS_Store -type f -delete
Point it at the drive or directory you want swept. Together — the USB key for external volumes, the global gitignore for repos, and one cleanup pass — .DS_Store stops showing up where it doesn't belong.
Mainspring turns the "don't write .DS_Store on USB drives" setting into a labelled, reversible toggle — the external-drive half of the fix, without the Terminal or the logout guesswork. It's one of 90+ hidden macOS settings made one click away.
Try Mainspring free →Signed & notarized by Apple · 1-day free trial · $29 once
Purge them from an existing project fast
If a repo is already full of committed .DS_Store files across many folders, a bulk cleanup beats deleting them by hand — see how to delete .DS_Store files on Mac for a one-command sweep.