---
title: "How do I set up a global .gitignore for files like .DS_Store?"
description: "Stop committing .DS_Store, editor folders and other personal clutter in every repository by setting up one global ignore file with core.excludesFile."
url: https://www.danny.engineering/answer/git/how-do-i-set-up-a-global-gitignore-for-files-like-ds_store
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T18:57:00.000Z
tags: ["Git"]
---

# How do I set up a global .gitignore for files like .DS_Store?

## The short answer


Create one ignore file for your machine and point Git at it with `core.excludesFile`. Every repository on your computer then ignores those patterns, without you adding them to each project's `.gitignore`.


```bash
printf '.DS_Store\n.idea/\n*.swp\n' >> ~/.gitignore_global
git config --global core.excludesFile ~/.gitignore_global
```


## Why it happens


Some files come from your operating system or editor, not from the project. macOS creates `.DS_Store` in folders you open in Finder, Windows creates `Thumbs.db`, and editors create folders such as `.idea/` or swap files ending in `.swp`.


You could add them to every project's `.gitignore`, but they are about your machine, not the code. Other contributors on different systems have different clutter, and project ignore files fill up with entries that have nothing to do with the project.


Git reads ignore patterns from three places, from most specific to least:

- `.gitignore` files in the repository, shared with everyone.
- `.git/info/exclude`, private to one clone.
- The global file set by `core.excludesFile`, private to your user account and used in every repository.

## How to fix it


### Create the global ignore file


Put your personal patterns in a file. The name does not matter; this example uses `~/.gitignore_global`:


```bash
# ~/.gitignore_global

# macOS
.DS_Store
.AppleDouble

# Windows
Thumbs.db
Desktop.ini

# Editors
.idea/
*.swp
*~
```


Then tell Git where it is:


```bash
git config --global core.excludesFile ~/.gitignore_global
git config --global core.excludesFile     # print the value to check
```


### Or use the default location


If `core.excludesFile` is not set, Git already looks in `$XDG_CONFIG_HOME/git/ignore`, which is `~/.config/git/ignore` when that variable is not set. Putting your patterns there works without any config:


```bash
mkdir -p ~/.config/git
echo ".DS_Store" >> ~/.config/git/ignore
```


Pick one approach. If `core.excludesFile` is set, Git uses that file instead of the default one.


### Check that a file is ignored


`git check-ignore -v` shows which file and line ignored a path, which is very useful when a rule does not seem to apply:


```bash
git check-ignore -v .DS_Store
# /Users/sam/.gitignore_global:4:.DS_Store	.DS_Store
```


No output means the path is not ignored.


### Stop tracking files that were already committed


Ignore rules only apply to untracked files. If `.DS_Store` files are already in the repository, remove them from the index and commit:


```bash
git rm -r --cached --ignore-unmatch .DS_Store '**/.DS_Store'
git commit -m "Stop tracking .DS_Store files"
```


The files stay on your disk; only Git stops tracking them.


### Keep project rules in the project


The global file is for things specific to you. Anything every contributor would generate, such as `node_modules/`, build output or `.env` files, belongs in the project's `.gitignore` so it protects everyone, including CI and new team members.


## Common pitfalls

- Writing the file but never setting `core.excludesFile`, or setting it with a typo in the path. Check with `git config --global core.excludesFile`.
- Expecting the rule to remove files already committed. Ignoring only affects untracked files; use `git rm --cached` first.
- Relying on your global file for project essentials like `.env`. Teammates without the same global file will commit them.
- Setting `core.excludesFile` in a repository's local config instead of with `--global`, so it only works in that one repository.

## Related reading

- [Git documentation: gitignore](https://git-scm.com/docs/gitignore)
- [Git documentation: git check-ignore](https://git-scm.com/docs/git-check-ignore)
