# How to add a global .gitignore

> Stop committing .DS_Store, Thumbs.db, and IDE folders into every project. Learn how to configure a global .gitignore that applies across all your repositories.

- URL: https://blog.noobygames.de/blog/global-gitignore/
- Author: Tobias Theel
- Language: en
- Published: 2026-05-09
- Updated: 2026-11-13
- Tags: tutorial, git, developer-tooling
- Translation (de): https://blog.noobygames.de/de/blog/global-gitignore/

**TL;DR**

- A global `.gitignore` is a single file that Git applies to every repository on your machine, registered via the `core.excludesFile` config key.
- Run `git config --global core.excludesFile ~/.gitignore_global` to register the file; without that setting Git already reads `~/.config/git/ignore`.
- The global file belongs to OS, editor, and tool artifacts like `.DS_Store`, `Thumbs.db`, and `*.swp`; project-specific rules stay in the repository's `.gitignore`.
- Repository `.gitignore` files beat `.git/info/exclude`, which beats `core.excludesFile`, so a `!negation` in a project can re-include a globally ignored file.
- Already-tracked files stay tracked after you ignore them; run `git rm --cached <file>` first.

Every developer has done it at least once: accidentally committed a `.DS_Store` file, a `.idea/` folder, or some other machine-specific artifact into a shared repository. A per-project `.gitignore` helps, but you have to repeat yourself in every repo. A **global `.gitignore`** fixes that: it is a single file that Git applies to every repository on your machine.

## How Git decides what to ignore

Git evaluates ignore rules from three sources, in order of specificity:

1. `.gitignore` files inside the repository (committed, shared with the team)
2. `.git/info/exclude` inside the repository (local, not committed)
3. The file pointed to by `core.excludesFile` in your global Git config (applies to every repo on the machine)

The global exclude file is the right place for rules that are specific to **your machine or tooling**, not to a project. See the official [gitignore documentation](https://git-scm.com/docs/gitignore) for the full resolution order.

## Step 1: Create the file

By convention the file is named `.gitignore_global` and lives in your home directory, but you can place it anywhere and call it anything.

**Linux / macOS:**

```bash
touch ~/.gitignore_global
```

**Windows (PowerShell):**

```powershell
New-Item -ItemType File -Path "$env:USERPROFILE\.gitignore_global"
```

![PowerShell output of New-Item creating .gitignore_global](https://blog.noobygames.de/img/global_gitignore_new_item.png)

## Step 2: Tell Git about it

Register the file with Git via the `core.excludesFile` config key.

> **Shortcut:** when `core.excludesFile` is not set, Git already reads `$XDG_CONFIG_HOME/git/ignore`, falling back to `~/.config/git/ignore` (`%USERPROFILE%\.config\git\ignore` on Windows). Put your rules in that file and you can skip this step entirely. The explicit setting below is useful when you want the file somewhere else or want it to be obvious in your `.gitconfig`.

**Linux / macOS:**

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

**Windows (PowerShell):**

```powershell
git config --global core.excludesFile "$env:USERPROFILE\.gitignore_global"
```

This writes one line into `~/.gitconfig` (Linux/macOS) or `%USERPROFILE%\.gitconfig` (Windows):

```ini
[core]
    excludesFile = /home/you/.gitignore_global
```

You can verify it was written correctly:

**Linux / macOS:**

```bash
git config --global core.excludesFile
```

**Windows (PowerShell):**

```powershell
git config --global core.excludesFile
```

Both should print the path you set.

## Step 3: Populate the file

Anything your operating system, editor, or toolchain generates belongs here. Files the project itself produces do not.

A practical starting point:

```text
# macOS
.DS_Store
.AppleDouble
.LSOverride

# Windows
Thumbs.db
ehthumbs.db
desktop.ini

# Linux
*~
.nfs*

# Vim / Neovim
*.swp
*.swo
Session.vim

# Emacs
\#*\#
.\#*

# direnv
.envrc
```

Leave version-manager files such as `.tool-versions` (asdf, mise) or `mise.toml` out of this list. Many teams commit them on purpose to pin tool versions. Ignoring them globally hides them from `git status`, and you never notice when a colleague's change to them is missing from your commit.

Rules use the same glob syntax as a regular `.gitignore`. Blank lines and lines starting with `#` are ignored.

## Generating rules automatically

Maintaining this list by hand gets tedious. [gitignore.io](https://www.toptal.com/developers/gitignore) (also accessible via API) generates tailored ignore rules for any combination of operating systems, editors, and languages. For example, to get rules for macOS + Windows + JetBrains + Go in the terminal:

**Linux / macOS:**

```bash
curl -sL "https://www.toptal.com/developers/gitignore/api/macos,windows,jetbrains+all,go" \
  >> ~/.gitignore_global
```

**Windows (PowerShell):**

```powershell
Invoke-WebRequest -Uri "https://www.toptal.com/developers/gitignore/api/macos,windows,jetbrains+all,go" `
  -UseBasicParsing | Select-Object -ExpandProperty Content `
  | Add-Content -Path "$env:USERPROFILE\.gitignore_global"
```

The GitHub team also maintains a curated collection of templates at [github/gitignore](https://github.com/github/gitignore). Each file there covers one language or tool and is a reliable reference.

## Verify it works

Create a throwaway file that matches a rule and confirm Git ignores it:

**Linux / macOS:**

```bash
cd /tmp && git init test-repo && cd test-repo
touch .DS_Store
git status
```

**Windows (PowerShell):**

```powershell
$null = New-Item -ItemType Directory -Path "$env:TEMP\test-repo"; cd "$env:TEMP\test-repo"
git init
New-Item -ItemType File -Path "Thumbs.db"
git status
```

`git status` should report a clean working tree, because the file is invisible to Git.

![PowerShell output showing git status with no files tracked](https://blog.noobygames.de/img/global_gitignore_verify.png)

## Caveats

- **Sources have a fixed precedence.** Patterns in a repository's `.gitignore` files beat `.git/info/exclude`, which beats `core.excludesFile`. So a `!negation` in a project's `.gitignore` re-includes a file your global file ignores. Within a single source, the **last** matching pattern wins, even if an earlier one is more specific.
- **Already-tracked files are not affected.** If a file is already committed to a repository, adding it to any `.gitignore` (including the global one) will not untrack it. You need `git rm --cached <file>` first.
- **Team members need their own setup.** The global exclude file is purely local; it is never committed. If a pattern should apply to everyone on a project, put it in the project's `.gitignore` instead.

## Conclusion

You set up a global `.gitignore` once, and from then on it keeps OS, editor, and tool artifacts out of the commits in every repository on your machine. Keep it focused on machine- and tool-specific artifacts, and leave project-specific rules to the per-repository `.gitignore`.
