Global Gitignore: Set Up core.excludesFile on Any OS
November 11, 2026 · 9 min read
Global Gitignore: Set Up core.excludesFile and Local Excludes
A global gitignore is one ignore file that Git applies to every repository on your machine. It's the right home for .DS_Store, Thumbs.db and editor swap files. Git already reads ~/.config/git/ignore with no setup, or you can point core.excludesFile at any file you like.
Three Places Git Looks for Ignore Rules
Git doesn't read just one ignore file. It merges patterns from three kinds of file, and each one has a different audience:
| File | Applies to | Committed? | Typical contents |
|---|---|---|---|
.gitignore in the repo | Everyone who clones the repo | Yes | Build output, dependency folders, .env files |
.git/info/exclude | One repo, only on your machine | No | Personal scratch files, a local test script |
| Global excludes file | Every repo, only on your machine | No | OS junk, your editor's swap and settings files |
When rules disagree, the gitignore documentation sets the order. From highest to lowest, it's patterns on the command line, then .gitignore files, then .git/info/exclude, then the global file. So a repo can always override your personal rules, which is usually what you want.
For wildcards, negation and the other pattern rules, see the PATTERN FORMAT section of that git-scm page. This post sticks to where the files live and how to wire them up.
Where Is the Global Gitignore File by Default?
You may not need a git config command at all. Git reads $XDG_CONFIG_HOME/git/ignore by default. If XDG_CONFIG_HOME is unset or empty, it falls back to ~/.config/git/ignore, which is the path most macOS and Linux machines end up using.
The file usually doesn't exist yet, so create the folder and add your first rules:
mkdir -p ~/.config/git
printf '.DS_Store\nThumbs.db\n' >> ~/.config/git/ignore
That's the whole setup. Every repo on the machine now ignores those two files. GitHub Docs describe the same default path and warn that you may need to create the directory first.
On Windows, Git looks in your home folder, which is usually C:\Users\you, so the default file is C:\Users\you\.config\git\ignore. We prefer this zero-config path over a custom one. There's no setting in .gitconfig to mistype, and Git's own files stay together in one folder.
How to Use a Custom Path with core.excludesFile on macOS and Linux
Plenty of guides set up a git global gitignore at ~/.gitignore_global instead, and that works too. Create the file, then tell Git where it lives:
touch ~/.gitignore_global
git config --global core.excludesFile ~/.gitignore_global
git config --global --get core.excludesFile
The last command prints the stored path, such as /Users/you/.gitignore_global. If it prints nothing, the setting is missing from your global config.
Two details trip people up. First, setting core.excludesFile replaces the default path rather than adding to it. Once it's set, Git stops reading ~/.config/git/ignore, so move any rules you had there into the new file.
Second, quoting the tilde is fine. The git-config docs say Git expands a leading ~/ to your home directory itself. A value like '~/.gitignore_global' works even when your shell leaves the tilde alone.
How to Set a Global Gitignore on Windows
On Windows the commands depend on your shell, because cmd, PowerShell and Git Bash each read environment variables differently. Pick the block that matches the window you're typing in.
In Command Prompt, %USERPROFILE% expands to your user folder. The >> creates the file without wiping one that already exists:
type nul >> "%USERPROFILE%\.gitignore_global"
git config --global core.excludesFile "%USERPROFILE%\.gitignore_global"
PowerShell doesn't expand %USERPROFILE%. It reads environment variables through $env: instead. If the file already exists, New-Item reports an error, so skip that line:
New-Item -ItemType File -Path "$env:USERPROFILE\.gitignore_global"
git config --global core.excludesFile "$env:USERPROFILE\.gitignore_global"
Git Bash takes the same commands as macOS and Linux, because it expands ~ for you. Keep the double quotes in the cmd and PowerShell versions if your user name contains a space.
If you create the file in Notepad instead, check the name it saves under. Notepad can add a .txt extension, and File Explorer hides known extensions by default. Run dir "%USERPROFILE%\.gitignore*" in cmd to see the real file name.
A Starter Global Gitignore for macOS, Windows and Linux
Here's a short file that covers the junk each operating system leaves behind, starting with a macOS gitignore block. Paste it into whichever global file you set up above:
# macOS
.DS_Store
.AppleDouble
.LSOverride
._*
.Spotlight-V100
.Trashes
# Windows
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
# Linux
*~
.directory
.Trash-*
# Editors
*.swp
.idea/
The macOS lines are what most people want from a Mac gitignore. Finder writes .DS_Store into folders to remember view settings, and ._* files hold resource-fork data on drives that don't support it natively. .Spotlight-V100 and .Trashes appear at the root of external volumes.
On Windows, Thumbs.db and ehthumbs.db are thumbnail caches, and Desktop.ini stores folder settings. The Recycle Bin line covers the hidden folder Windows keeps at the root of each drive, which only matters if a repo sits at a drive root. On Linux, *~ catches editor backup copies, .directory comes from KDE's Dolphin file manager, and .Trash-* is the per-drive trash folder.
The editor lines need a judgement call. Ignoring all of .idea/ means any new file your team wants to share from that folder needs git add -f, so drop that line if your team commits shared IDE settings. The same applies to .vscode/. If VS Code is also where you write Markdown, our VS Code Markdown guide covers its preview, extensions and settings.
You don't have to assemble this by hand. The .gitignore generator has templates for macOS, Windows, Linux and editors such as VS Code, JetBrains, Vim and Emacs. Tick the ones you need, copy the output and paste it into your global file yourself.
What Belongs in the Global File and What Belongs in the Repo
A simple test works for most cases. If a file comes from your machine or your habits, it goes in the global file. If it comes from the project, such as build output, dependency folders or .env files, it goes in the repo's .gitignore, because every contributor generates it. For a full project-level example, see our gitignore for Unity guide.
Our view is that OS and personal editor rules don't belong in shared repo files. A repo .gitignore that lists every operating system and IDE gets long, and most of its lines describe tools the project never uses.
There's a real limitation here, though. Your global file protects only you. A teammate without one can still commit .DS_Store, and CI never sees your rules. That's why many teams add the OS lines to the repo file anyway. Whichever way you go, write the convention down where contributors will see it. Our README Markdown guide shows how to structure that file.
When to Use .git/info/exclude for Local-Only Ignores
Some files are personal but matter in only one repo: a notes.md beside the code, a scratch/ folder, or a debug script with your local paths baked in. They don't belong in the shared .gitignore, and they're too specific for the global file. That's the job of .git/info/exclude, a local gitignore that sits inside the repo's .git folder.
echo 'notes.md' >> .git/info/exclude
echo 'scratch/' >> .git/info/exclude
Run these from the repository root. GitHub Docs note that rules in this file aren't checked in and only ignore files in your local repository. Because it lives inside .git, it isn't cloned either, so a fresh clone starts with the default exclude file, which holds only comments.
Why Isn't My Global Gitignore Working?
Start with git check-ignore -v, which names the exact file and line that matched a path:
git check-ignore -v .DS_Store
When the global rule fires, the output looks like this:
/Users/you/.config/git/ignore:1:.DS_Store .DS_Store
The first field tells you which scope fired. Per the git check-ignore docs, the global file shows up as an absolute path, while .gitignore and .git/info/exclude show up relative to the repo. No output means no rule matched.
If the rule you expect isn't there, one of these is usually the cause:
- The file is already tracked. Ignore rules never apply to tracked files, and
check-ignoreskips them unless you add--no-index. Rungit rm --cachedon the file to stop tracking it. - You set
core.excludesFileand forgot the default. Rules in~/.config/git/ignorego quiet once the setting points elsewhere. Put them in the file thatgit config --global --get core.excludesFileprints, or rungit config --global --unset core.excludesFileto go back to the default path. - The configured path doesn't exist. A typo, a different home folder or a hidden
.txtextension means Git reads nothing, and it doesn't warn you. - A repo rule re-includes the file. A line such as
!.DS_Storein the repo's.gitignoreoutranks your global rule.check-ignore -vshows that line with its leading!, which means the path isn't ignored.
A global gitignore takes a couple of commands to set up and keeps OS and editor clutter out of every repo you touch. Use the default ~/.config/git/ignore or point core.excludesFile at your own file, keep project rules in the repo, and reach for git check-ignore -v when something slips through. To build the starter list faster, pick your OS and editor templates in the .gitignore generator and paste the result into your file.