How do I ignore .DS_Store in every directory?

A .DS_Store rule without a leading slash covers that filename at any depth below the .gitignore. If Git still shows a modification, check whether the file is already tracked.

1. Add a rule with the right scope

Add this line to the root .gitignore to share the exclusion across the project. /.DS_Store would cover only the root copy. For a personal preference across repositories, use a global ignore file instead.

.DS_Store

Why is a file ignored by global Git rules?

2. Distinguish ignored files from tracked files

For untracked sample copies, inspect which rule matches each path:

git check-ignore -v -- .DS_Store assets/.DS_Store

Then check whether these specific paths are already in the index. Verbose check-ignore normally omits tracked files; a matching ignore rule does not stop tracking them.

git ls-files -- .DS_Store assets/.DS_Store

3. Stop tracking a specific copy

If assets/.DS_Store is tracked, first review its state and save any needed local work, then remove just its index entry:

git rm --cached -- assets/.DS_Store

Review the staged deletion before committing. --cached keeps your current local copy, but collaborators may lose their tracked copy when they pull the deletion. Repeat only for paths you have inspected; avoid a broad filesystem deletion or rebuilding the entire index.

git diff --cached --name-status

How do I ignore files Git already tracks?

For exact behavior and further details, consult the official references: Git documentation · git rm documentation · git check-ignore documentation