TIL: .git/info/exclude - ignore files without touching .gitignore
Every Git repository has a file at .git/info/exclude that works exactly like .gitignore, but only for you. It's not tracked and not committed. Nobody else on the team even knows it's there.
Why you'd want this
You're debugging something and you create a notes.txt or test-output.log in the repo. Or you use a tool that generates files your teammates don't care about. You don't want to commit these files, but adding them to .gitignore means committing a .gitignore change. For your personal scratch files. That feels wrong.
How to use it
Open .git/info/exclude in any text editor. It already exists in every Git repo - created automatically when you run git init or git clone.
Add your patterns. Same syntax as .gitignore:
Done. Git ignores these files for you, nobody else is affected, no commits needed.
When to use which
.gitignore is for things the whole team should ignore: node_modules/, dist/, .env, build artifacts.
.git/info/exclude is for things only you need to ignore: personal scratch files, editor configs that aren't standard for the team, temporary debugging output, one-off scripts you wrote for yourself.
Global gitignore (~/.gitignore_global or core.excludesFile) is for things you want ignored across all your repos: .DS_Store, Thumbs.db, your editor's files.
Setting up global gitignore
If you haven't set one up yet:
The hierarchy
Git checks ignore rules in this order (later ones can override earlier ones):
.gitignorein the repo (shared with team).git/info/exclude(just you, this repo)- Global gitignore via
core.excludesFile(just you, all repos)
I've been using Git for years and only recently found out about .git/info/exclude. It's one of those features that's been there the whole time, just never mentioned in any tutorial I've read.
