Ignoring macOS .DS_Store Files in Git

How to properly ignore .DS_Store files in git. Covers local and global gitignore approaches, plus removing already-tracked .DS_Store files from repositories.

System

Detailed Explanation

.DS_Store (Desktop Services Store) is a hidden file automatically created by macOS Finder in every directory you open. It stores custom folder attributes like icon positions, view settings, and background images. These files are completely useless in a git repository and create noisy, meaningless diffs.

The problem:

Every macOS developer on your team generates .DS_Store files. If even one person forgets to ignore them, they end up committed and cause merge conflicts. Since Finder creates them in every directory, a single repository can accumulate dozens of these files.

Local project .gitignore approach:

Add this pattern to your project's .gitignore:

.DS_Store
**/.DS_Store

The **/.DS_Store pattern catches files in all subdirectories. The root-level .DS_Store pattern is technically redundant when using **/, but many developers include both for clarity.

Global gitignore approach (recommended):

Since .DS_Store is an operating system artifact, the cleanest solution is to configure a global gitignore that applies to all your repositories:

git config --global core.excludesFile ~/.gitignore_global

Then add .DS_Store to ~/.gitignore_global. This way, you never need to add it to individual project .gitignore files, and non-macOS teammates are not bothered by macOS-specific patterns.

Removing already-tracked .DS_Store files:

If .DS_Store files were already committed, adding them to .gitignore will not remove them. You must explicitly untrack them:

git rm --cached **/.DS_Store
git commit -m "Remove tracked .DS_Store files"

The --cached flag removes them from git without deleting the local files. After this commit, the .gitignore rule takes effect for future operations.

Other macOS files to ignore: .AppleDouble, .LSOverride, Icon\r, ._* (resource forks created on non-native file systems), .Spotlight-V100, and .Trashes.

Use Case

A cross-platform team with macOS and Linux developers keeps getting .DS_Store merge conflicts and needs a permanent solution to exclude these system files.

Try It — .gitignore Generator

Open full tool