Git basics

Remove .DS_Store files from a Git repo

Take macOS's .DS_Store files out of your repo and stop them coming back.

  1. Stop tracking every .DS_Store
    Terminal
    find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch
  2. Ignore them from now on
    Terminal
    echo .DS_Store >> .gitignore
  3. Commit
    Terminal
    git add .gitignore && git commit -m "Remove .DS_Store files"
  1. Stop tracking every .DS_Store
    Terminal · Ubuntu / Debian
    find . -name .DS_Store -print0 | xargs -0 git rm --cached --ignore-unmatch
  2. Ignore them from now on
    Terminal · Ubuntu / Debian
    echo .DS_Store >> .gitignore
  3. Commit
    Terminal · Ubuntu / Debian
    git add .gitignore && git commit -m "Remove .DS_Store files"
  1. Stop tracking every .DS_Store
    PowerShell
    git ls-files '*.DS_Store' | ForEach-Object { git rm --cached --ignore-unmatch $_ }
  2. Ignore them from now on
    PowerShell
    Add-Content .gitignore .DS_Store
  3. Commit
    PowerShell
    git add .gitignore; git commit -m "Remove .DS_Store files"