Amit Jotwani

Amit Jotwani

How to Globally Ignore .DS_Store Files in Git Repositories on a Mac

Tinkering

So, I got tired of adding `.DS_Store` to every git repo on my Mac. I was pretty sure there would be a better way to handle this on a global way on my Mac, so I don't have to do this for every repo.

Here's what I found: You can create a global `.gitignore` file, add .DS_Store to it, and have git ignore them in all my repositories at once.

1. Create a Global Git Ignore File

Open up your favorite Terminal app, and type the following -


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

This command tells Git where the global `.gitignore` file is located or creates it if it doesn't exist.

2. Edit the Global Git Ignore File

Next, I had to edit this file to include the `.DS_Store` pattern.

Open this global git ignore file in your favorite Text Editor (e.g., nano or vim)
```bash
nano ~/.gitignore_global
```

Add the file/folder patterns you would like to ignore for all your repos to `.gitignore_global`
```
.DS_Store
```

By adding this line, I told Git to ignore `.DS_Store` files globally.

3. Apply the Changes

Finally, to apply the changesr run the same configuration command again:


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

And that's it! No more manually adding `.DS_Store` to each individual repository's `.gitignore` file. Now, my Mac ignores these files in all Git repositories.