Search code examples
gitgitignore

When would you use .git/info/exclude instead of .gitignore to exclude files?


I am a bit confused about the pros and cons of using .git/info/exclude and .gitignore to exclude files.

Both of them are at the level of the repository/project, so how do they differ and when should we use .git/info/exclude ?


Solution

  • The first advantage of .gitignore is that it is versioned into the repository itself, unlike .git/info/exclude. The second advantage is that you can have multiple .gitignore files, one per directory/subdirectory, for directory specific ignore rules, unlike .git/info/exclude.

    So the .gitignore files are versioned and present across all clones of the repository. Therefore, in large teams all people are ignoring the same kind of files (e.g. *.db, *.log); and using several .gitignore files allow for more specific ignore rules.

    .git/info/exclude is available for individual clones only. It is not versioned, hence what one person ignores in their clone is not available/present in another person's clone. For example, if someone uses Eclipse for development, it may make sense for that developer to add .build folder to .git/info/exclude because other devs may not be using Eclipse.

    In general, files/ignore rules that have to be universally ignored should go in .gitignore, and otherwise files that you want to ignore only on your local clone should go into .git/info/exclude.