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
| Situation | Examples | Recommended location |
|---|---|---|
| Personal files used only in this repository | notes.md, scratch/, todo.txt | .git/info/exclude |
| Personal files common to all repositories | .DS_Store, *.swp | Global gitignore |
| Rules every teammate needs | node_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.
- Command-line patterns
.gitignore(files in subdirectories override those above).git/info/excludecore.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
- It has no effect on files that are already tracked. As with .gitignore, ignore rules apply only to untracked files.
- A fresh clone resets this file to its default state. If you need the same rules on several computers, a global gitignore is the better choice.
- If you copy a repository to a shared folder and the
.gitdirectory is copied too, the rules come along with it.
References
- gitignore official documentation: $GIT_DIR/info/exclude
- GitHub Docs: Excluding local files without creating a .gitignore file
- Verified as of: 2026-09-23 (precedence example checked with git 2.50.1)