Search code examples
gitversion-controlgitignore

When would you use .git/info/exclude instead of ~/.gitignore (core.excludesFile) to exclude files?


I am little bit confused as to when would you use .git/info/exclude instead of ~/.gitignore (core.excludesFile) to exclude files? I am clear when to use .gitignore file present in project repository which is specific to that project, version-controlled and shared with other repo via clone but I am unable to understand difference between the above two somewhat user specific files to be ignored.

Thus, I am looking for difference between ~/.gitignore and .git/info/exclude and not between .gitignore (project dir) and .git/info/exclude.

UPDATE: I am unable to think specific usage of .git/info/exclude as whatever files I want to ignore either fall in .gitignore or ~/.gitignore. It would really help if somebody can give an example for pattern/file that should specifically be included in .git/info/exclude.


Solution

  • Placing a file name or pattern in your global ignore file (~/.gitignore or $XDG_CONFIG_HOME/git/ignore) will suppress complaints about it in all repositories. Placing the same name or pattern in the per-repository ignore file (.git/info/exclude) will suppress complaints only for that one repository.

    Neither of these is inherently superior or inferior; they're just different. It's worth noting that ancient Git supported only the in-repository .gitignore and .git/info/exclude files, i.e., had no per-user, global ~/.gitignore.

    If you personally use an editor that makes backup files whose name ends with (say) $ instead of .bak or .~, and everyone else doesn't (and the everyone-else's backup files are already in a committed .gitignore), you might put *$ in your personal ~/.gitignore. If you only use this editor with this one project, it might make more sense to put this in .git/info/exclude.

    If the project itself makes a lot of to-be-ignored files, it makes sense to put these names into .gitignore files that are committed into the project, but if there is some reason that this cannot be done, it then makes sense to put these patterns into .git/info/exclude: they should not be ignored in other projects.