Git Reference ยท Files and Formats
The .git/info/exclude file
Reference for .git/info/exclude: a per-clone ignore file that is never committed, how it ranks against .gitignore, and when to use it instead.
.git/info/exclude is an ignore file that lives inside the repository's private directory. It uses exactly the same pattern syntax as .gitignore, but it is not part of the project: it is never committed, never pushed and never cloned. Each clone has its own copy, created by git init with a few explanatory comment lines.
Use it for rules that matter only to you in this one repository: a scratch directory, a personal notes file, a local build folder that other contributors do not have. For rules you want in every repository on your machine, use a global excludes file instead; for rules the whole team needs, use .gitignore.
echo "scratch/" >> .git/info/exclude git status --short --ignored
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
The file is plain text, one pattern per line, with # comments. Location: .git/info/exclude in the repository's common directory. The path is $GIT_DIR/info/exclude; in a linked worktree the file of the main repository is used for all worktrees.
| Property | Behavior |
|---|---|
| Syntax | Same as .gitignore (see Gitignore-style patterns). |
| Relative to | The top of the working tree, so /build/ anchors to the repository root. |
| Priority | Lower than every .gitignore in the tree, higher than core.excludesFile. |
| Shared | Never. Not part of any commit, push or clone. |
Errors and edge cases: if the info directory is missing (for example after a repository was created with a custom --template), create it by hand: mkdir -p .git/info. A bare repository has info/exclude too, but it has no working tree to apply it to.
Usage notes
- Precedence caveat: because
.gitignoreoutranks the exclude file, a!patternin.gitignorecan re-include something you excluded locally, as in the second example. Last-match-wins is applied within each source, and sources are consulted from highest to lowest priority. - Tracked files still ignore the rule. Like every ignore mechanism, it only hides untracked files.
- No need to commit anything. Editing the file does not create changes in
git status, which makes it ideal for noting local scratch files without bothering the team. - Per-user alternative: a global file at
~/.config/git/ignore(or any path set incore.excludesFile) covers every repository you use; see core.excludesFile. - Not a hiding place for tracked changes. To keep changes to a tracked file out of
git status, see git update-index --assume-unchanged. - Backups: the file is inside
.git, so deleting the repository directory or re-cloning loses it. Keep important personal rules in the global file instead. - Debugging:
git check-ignore -v <path>prints.git/info/exclude:8:*.localstyle output (file, line number and pattern). The line number depends on how many comment lines the template gave you.
Related
- .gitignore, core.excludesFile, The .git directory
- Lessons: Gitignore