The Hidden Litter
Every time you open a folder in Finder on macOS, the system silently creates a hidden file called .DS_Store inside that directory. This file stores custom view settings for the folder — icon positions, view type (list, column, gallery), sort order, and background colour. While invisible to most Mac users, .DS_Store files become a visible nuisance when shared via version control systems like Git, uploaded to web servers, transferred to USB drives formatted for Windows, or shared with colleagues via network drives. These tiny metadata files clutter repositories, trigger unnecessary Git diffs, and can even leak internal directory names when deployed to public-facing web servers.
Preventing .DS_Store File Creation on Network Drives
To stop macOS from automatically creating .DS_Store files on network volumes and USB drives, you can adjust a system default. Unfortunately, Apple does not provide a way to prevent their creation on local drives without third-party tools.
Open Terminal. To prevent .DS_Store files from being created on network volumes (SMB shares, NFS mounts, AFP servers), run: defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true. To also prevent them on USB volumes, run: defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true. Log out and log back in for the changes to take effect. After this, Finder will no longer litter shared network drives and removable media with .DS_Store files. For local drives, the files will still be created, but you can manage them via .gitignore (add .DS_Store to your global gitignore file with echo ".DS_Store" >> ~/.gitignore_global and git config --global core.excludesfile ~/.gitignore_global). To remove existing .DS_Store files from a project directory, run find . -name ".DS_Store" -delete.