Global Ignore Files

Global Gitignore and Attributes Files

Editor swap files and .DS_Store come from your machine, not from the project, so they belong in your own ignore file rather than in every repository's .gitignore (.gitignore for Node.js). Git 1,932 reads ~/.config/git/ignore and ~/.config/git/attributes without any setting ($XDG_CONFIG_HOME/git/ if that variable is set); core.excludesFile and core.attributesFile choose other paths:

A personal ignore file and a personal attributes fileShell
mkdir -p ~/.config/git
printf '%s\n' '*.swp' '.DS_Store' '.idea/' > ~/.config/git/ignore
touch notes.swp && git check-ignore -v notes.swp && rm notes.swp
echo 'package-lock.json -diff' > ~/.config/git/attributes
git diff v1.1.0 -- package-lock.json
Output
/home/dev/v5-ch2/home/.config/git/ignore:1:*.swp        notes.swp
diff --git a/package-lock.json b/package-lock.json
index 604b5a8..de047e8 100644
Binary files a/package-lock.json and b/package-lock.json differ

git check-ignore -v names the file, line and pattern responsible. The -diff attribute makes Git treat the lockfile as binary in diffs, so a dependency update no longer buries the code changes; git diff --text shows it anyway. The global file has the lowest priority, below .git/info/exclude and each .gitignore, and anything the whole team needs still belongs in the repository.