How to delete .DS_Store files on Mac
Open any project folder in a code editor and you'll often find a .DS_Store file sitting there — not from you, just macOS. They're harmless on your own machine but notorious for sneaking into git commits, polluting shared drives, and confusing teammates on Windows or Linux who have no idea what they are.
What .DS_Store files actually are
Every time Finder opens a folder, it creates or updates a hidden file called .DS_Store (Desktop Services Store). This file stores Finder-specific metadata for that folder: icon positions, the chosen view (list, icon, column), background color, and window size. It's Apple's way of remembering how you left a folder so it looks the same when you come back.
The file is invisible by default (it starts with a dot), so most users never see it. But it's always there — in every folder Finder has touched, including your git repos, USB drives, and shared network folders.
Why they're a problem
.DS_Store files cause friction in a few specific situations:
- Git repositories: If you forget to ignore them, every developer on a project ends up committing pointless Finder metadata. Even if only one person on the team uses a Mac, their .DS_Store will show up in
git statusfor everyone. - Shared folders and USB drives: Drop a USB stick into a Windows PC and you'll see a tiny .DS_Store file in every folder. Harmless, but messy and confusing.
- Zip archives: Archive a project folder and .DS_Store files get bundled inside. The recipient has to manually delete them.
Delete all .DS_Store files in a folder
To nuke every .DS_Store in a directory and all its subdirectories, open Terminal, navigate to the folder, and run:
# delete all .DS_Store files in current directory and subfolders
find . -name ".DS_Store" -delete
To clean a specific path without navigating there first:
# target a specific project folder
find ~/Documents/my-project -name ".DS_Store" -delete
To clean your entire home directory (takes a moment on large drives):
find ~ -name ".DS_Store" -delete
These files will come back the next time Finder opens those folders — deleting them is a cleanup step, not a permanent fix. For a permanent fix, see the sections below.
Keep .DS_Store out of every git repo
The most practical solution is a global .gitignore that applies to all your projects, so you never have to think about it per-repo:
# add .DS_Store to a global gitignore file
echo '.DS_Store' >> ~/.gitignore_global
# tell git to use this file for all repos
git config --global core.excludesfile ~/.gitignore_global
From this point on, git will silently ignore .DS_Store files in every repository on your machine. You don't need to add it to each project's .gitignore. (Though it's still good practice to include it there too, so teammates on other Macs get the same benefit.)
If a .DS_Store has already been committed to a repo, you'll need to untrack it:
# remove a tracked .DS_Store from git (keeps the file on disk)
git rm --cached .DS_Store
git commit -m "Remove .DS_Store from tracking"
Stop them appearing on network and USB drives
There's a macOS preference that tells Finder not to create .DS_Store files on network volumes and external drives — the places where they're most annoying:
# stop .DS_Store files on network and USB volumes
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
Log out and back in (or restart) for this to take effect. To undo:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool false
Note that this only stops .DS_Store creation on external and network volumes — Finder will continue creating them inside your local home folder. For a full walkthrough of this setting, see the dedicated guide: stop .DS_Store files on network drives.
Mainspring turns dozens of these buried macOS settings — including the network .DS_Store toggle — into one-click, reversible switches. No Terminal, no half-remembered commands. Flip a setting on, see it work, flip it back if you change your mind.
Try Mainspring free →Signed & notarized by Apple · 1-day free trial · $29 once
Should you delete .DS_Store files on your local Mac?
On your own machine, they're completely harmless. Finder uses them to remember how you arranged folders — deleting them just means Finder starts fresh with default view settings next time you open those folders. You won't break anything, but there's no real benefit to deleting them locally either. The genuine wins come from keeping them out of git and off shared drives.