Global .gitignore Configuration Guide
Set up a global .gitignore for OS and editor files across all repositories. Covers configuration steps, common patterns, and global vs project-level usage.
Detailed Explanation
A global gitignore is a personal ignore file that applies to every git repository on your machine. It is the ideal place for operating system artifacts and editor-specific files that should never be committed, regardless of the project.
Setting up a global gitignore:
git config --global core.excludesFile ~/.gitignore_global
This tells git to read ~/.gitignore_global (you can name it anything) in addition to each project's .gitignore. The patterns in this file are applied universally.
Recommended global patterns:
macOS:
.DS_Store
.AppleDouble
.LSOverride
._*
.Spotlight-V100
.Trashes
Windows:
Thumbs.db
ehthumbs.db
Desktop.ini
$RECYCLE.BIN/
Linux:
*~
.directory
.Trash-*
Editors and IDEs:
.idea/
.vscode/
*.swp
*.swo
*~
*.sublime-workspace
*.sublime-project
When to use global vs. project-level:
Use the global gitignore for:
- Operating system files (
.DS_Store,Thumbs.db) — these are personal environment artifacts, not project concerns. - Editor/IDE files (
.idea/,.vscode/) — especially on teams with diverse editor choices. Putting every editor's patterns in the project.gitignorecreates clutter.
Use the project .gitignore for:
- Language-specific artifacts (
node_modules/,target/,__pycache__/) — these ARE project concerns and should be documented in the repo. - Framework build output (
.next/,dist/) — critical for every contributor to understand. - Environment files (
.env) — security-sensitive patterns belong in the project file so all contributors benefit.
Team coordination: Global gitignore files are personal and not shared via git. Provide a recommended setup in your project's CONTRIBUTING.md so new team members configure their machines correctly.
Checking if it works: Run git config --global core.excludesFile to verify the path, then git check-ignore -v <filename> to confirm a specific file is being ignored and identify which rule is responsible.
Use Case
A developer working on 30+ repositories wants to stop adding .DS_Store and .idea/ patterns to every single project and instead configure a single machine-wide ignore file.