Git Reference ยท Configuration Options
core.excludesFile setting
Reference for core.excludesFile: set up a global ignore file for editor and OS clutter, learn its default location and where it ranks among ignore sources.
core.excludesFile points to a file of ignore patterns that applies to every repository you use. It is meant for things that belong to your machine, not to any project: .DS_Store, Thumbs.db, editor swap files, .idea/, *.swp. Putting those into each project's .gitignore forces your tools on your colleagues; a global file keeps them out without that.
The file uses the normal .gitignore syntax. If you do not set the option, Git reads $XDG_CONFIG_HOME/git/ignore, which is ~/.config/git/ignore when XDG_CONFIG_HOME is not set.
git config --global core.excludesFile ~/.gitignore_global printf '.DS_Store\n*.swp\n.idea/\n' > ~/.gitignore_global
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
git config --global core.excludesFile <path>
| Name | Description |
|---|---|
<path> |
Path to the ignore file. A leading ~/ expands to your home directory. Relative paths are not useful: use an absolute one. |
Precedence (highest first): command-line patterns, then .gitignore files (a deeper directory beats a shallower one), then .git/info/exclude, then the global file. Within one file the last matching pattern wins, and a ! pattern can re-include a file ignored at a lower level.
Usage notes
- Only untracked files are affected. A file that is already tracked stays tracked; remove it with
git rm --cached. - Not shared. Nobody else gets your global file, so never rely on it for build output the project itself generates.
- Do not ignore wanted patterns globally. A global
*.logcan hide a file you meant to commit; Git shows nothing and you may only notice later.git check-ignore -v <path>names the exact rule. - Per-repository version:
.git/info/excludeworks the same way for a single repository and is also not committed. - Directories: a pattern ending in
/matches directories only;.idea/is the usual form. - No change needed on new machines: keep the file in your dotfiles repository and add one
git configline to your setup script. - Ignored does not mean absent:
git clean -xstill deletes ignored files, which is how global junk disappears.