Managing .DS_Store Files in Git: How to Ignore and Remove Them

How to prevent these from appearing…

Step 1: Add .DS_Store to .gitignore

  1. Add .DS_Store to your .gitignore file.

  2. Run:

    git add .gitignore
    git commit -m "Add .DS_Store to .gitignore"
    

Step 2: Remove Existing .DS_Store Files

  1. Run:

    find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch --cached
    
  2. Commit and push:

    git commit -m "Remove all .DS_Store files"
    git push
    

Source: https://github.com/desktop/desktop/issues/15644#issuecomment-2042535667