Global .gitignore
Some files you never want in any Git repo, regardless of the project — OS metadata, editor swap files, your personal IDE settings. Instead of adding them to every project’s .gitignore, configure a global ignore file that applies to every repo on your machine.
What belongs in a global ignore
Operating system files —
.DS_Store(macOS),Thumbs.db(Windows),*~(Linux backups).Editor swap files —
*.swp,*.swo,*~,#*#(Emacs).Your personal IDE settings —
.idea/workspace.xml,.vscode/launch.json(if you do not share them).System backup files —
*.bak,*.orig.Anything unique to your personal workflow that no teammate ever needs.
What does NOT belong in a global ignore
Project-specific patterns like
node_modules/ordist/. Those go in the project’s.gitignoreso every contributor sees the same rules.Anything you would want a teammate to also ignore. Global rules apply only to you.
Set up a global ignore
Two-step setup
# 1. Create a file (path is up to you) touch ~/.gitignore_global # 2. Tell Git to read it git config --global core.excludesFile ~/.gitignore_global
A practical starter
~/.gitignore_global
# ─── macOS ─── .DS_Store .AppleDouble .LSOverride Icon ._* .Spotlight-V100 .Trashes # ─── Windows ─── Thumbs.db ehthumbs.db Desktop.ini $RECYCLE.BIN/ # ─── Linux ─── *~ .fuse_hidden* .directory .Trash-* # ─── Editors ─── *.swp *.swo *~ .vscode/launch.json # personal debug configs .idea/ # if you do NOT want IDEA settings in any repo *.iml .history/ # ─── Misc ─── *.bak *.orig *.tmp
Default location
If you do not set core.excludesFile, Git looks at $XDG_CONFIG_HOME/git/ignore (typically ~/.config/git/ignore). Using that path means you do not have to configure anything:
mkdir -p ~/.config/git touch ~/.config/git/ignore # Add your patterns there — Git finds it automatically
Verifying it works
# In any repo: touch .DS_Store git status # .DS_Store should NOT appear as untracked # To see which file ignored it: git check-ignore -v .DS_Store # /Users/you/.gitignore_global:1:.DS_Store .DS_Store
Precedence
Per-file
.gitignore(closest to the file) — highest precedence.Repo-wide
.gitignorefiles (root and parent folders)..git/info/exclude— private to this clone, not committed.Global excludesFile (
~/.gitignore_globalor~/.config/git/ignore) — lowest precedence.Within each, later rules override earlier rules (and
!negations re-include).
Repo-private excludes — .git/info/exclude
If you have local files you want to ignore only in this clone — without touching the shared .gitignore — add them to .git/info/exclude. The file uses the same syntax as .gitignore but is not committed.
echo "scratch.txt" >> .git/info/exclude # scratch.txt is now ignored in this clone only
GitHub-style templates
GitHub publishes a curated Global folder at https://github.com/github/gitignore/tree/main/Global — drop-in files for OSes, editors, and tools.
Copy the patterns relevant to you into
~/.gitignore_globaland trim as needed.Update them once a year — new tools introduce new junk files.
git config --global core.excludesFile once → you never have to type these rules again.