---
title: "How remove .DS_Store files from a Git repository?"
url: "https://alex.zappa.dev/blog/how-remove-dsstore-files-from-a-git-repository/"
description: "Learn how to remove .DS_Store files from your Mac OS X repository. Use commands to find and remove the files. Update .gitignore for future prevention. Check gitignore.io for more configurations."
---

# How remove .DS\_Store files from a Git repository?

April 10, 2019

*   [#git](/tags/git/),
*   [#ds\_store](/tags/ds_store/),
*   [#macos](/tags/macos/)

Mac OS X users can include system .DS\_Store files to repository accidentally.

First, you can check how much .DS\_Srore files you have on your work directory. Use fallow command:

```
find .* -name ".DS_Store" -type f
```

To remove all .DS\_Store files from git you can use fallowing command:

```
find .* -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
```

## Update .gitignore file

Add to the file `.gitignore`, which can be found at the top level of your repository (or created if it isn’t there already).

You can do this easily with this command in the top directory:

```
echo "# Apple macOS\n.DS_Store\n.DS_Store?\n*/.DS_Store" >> .gitignore
```

Then add and commit your new `.gitignore` file

```
git add .gitignore && git commit -m '.DS_Store banished!'
```

## Avoid this issue in future

```
echo "# Apple macOS\n.DS_Store\n.DS_Store?\n*/.DS_Store" >> ~/.gitignore_global
```

Set the global git configuration

```
git config --global core.excludesfile ~/.gitignore_global
```

Admire your great work?

Also, check [gitignore.io](https://www.toptal.com/developers/gitignore/) where you can configure your own `.gitignore` file by few clicks.

May the 4th be with you,  
Alex

*   [PreviousHow do I find my Bitly OAuth access token?](/blog/how-do-i-find-my-bitly-oauth-access-token/)
*   [Next How to block visitors by country with the NGINX GeoIP Module (Debian/Ubuntu)](/blog/how-to-block-visitors-by-country-with-the-nginx-geoip-module-debianubuntu/)