VelvetShark

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.

code .git/info/exclude

Add your patterns. Same syntax as .gitignore:

# My debug files
debug-*.log
notes.txt
scratch/

# Editor-specific stuff I don't want in .gitignore
.idea/
*.swp

# Temporary test data
test-output/

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:

# Create the file
touch ~/.gitignore_global

# Tell Git about it
git config --global core.excludesFile ~/.gitignore_global

# Add your OS/editor noise
echo ".DS_Store" >> ~/.gitignore_global
echo "Thumbs.db" >> ~/.gitignore_global
echo "*.swp" >> ~/.gitignore_global

The hierarchy

Git checks ignore rules in this order (later ones can override earlier ones):

  1. .gitignore in the repo (shared with team)
  2. .git/info/exclude (just you, this repo)
  3. 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.

Shark footer