guide

Writing Your Own Ignore Rules with .git/info/exclude

How to write personal ignore rules that apply to a single repository in .git/info/exclude without editing .gitignore, when it is useful, and where it sits in precedence.

.gitignore is committed and shared with everyone. But sometimes there are files that only you want to ignore in this repository: personal notes, experimental scripts, folders created by your editor plugins and so on. For these cases, use .git/info/exclude.

Where it is

git init and git clone create the .git/info/exclude file by default. It is an empty file containing only a few comment lines.

cat .git/info/exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# ...

Because it lives inside the .git directory, it is not committed and is not delivered to anyone else when you push. The syntax is exactly the same as .gitignore. If you want to know the exact location, including when you use multiple worktrees, check it with git rev-parse --git-path info/exclude.

When to use it

SituationExamplesRecommended location
Personal files used only in this repositorynotes.md, scratch/, todo.txt.git/info/exclude
Personal files common to all repositories.DS_Store, *.swpGlobal gitignore
Rules every teammate needsnode_modules/, dist/, .env.gitignore

It is especially useful when contributing to someone else's repository. If you edit the project's .gitignore to block files your tools create, reviewers may not want that change. Writing them in .git/info/exclude leaves the commit history untouched.

echo 'scratch/' >> .git/info/exclude
echo '.my-plugin-cache/' >> .git/info/exclude
git status   # no longer shown

Precedence

Among the rule sources, .git/info/exclude is lower than .gitignore and higher than the global file.

  1. Command-line patterns
  2. .gitignore (files in subdirectories override those above)
  3. .git/info/exclude
  4. core.excludesFile

So you cannot restore a file ignored by .gitignore with a ! rule in .git/info/exclude. Checking it directly looks like this.

# .gitignore        : x
# .git/info/exclude : !x
$ git check-ignore -v x
.gitignore:1:x	x

Things to watch out for

References

← PreviousSetting Up a Global gitignore (core.excludesFile)