Best Practices for Git Ignore

The man pages for GIT aren’t usually the clearest or most helpful, and is seldom the first place I turn to for help. Still, I ran across some valuable “best practices” information which I myself have not been following due to ignorance.

I thought the only place to mark which files to hide was inside of a .gitignore file, ideally placed at the root of the repository. As a result, I would list all files and folders I may want to ignore inside of it. [1]

Instead, GIT has provided us with four places to provide file name patterns, each with its own intended purpose (some descriptions have been taken verbatim from the docs):

  • Sent as command line arguments (Only supported by some commands) – Mostly only useful for scripts or “temporary exceptions”.

  • A .gitignore file in the project directory – Patterns which should be version-controlled and distributed to other repositories via clone (i.e., files that all developers will want to ignore)

  • In the file .git/info/exclude – Patterns which are specific to a particular repository but which do not need to be shared with other related repositories (e.g., auxiliary files that live inside the repository but are specific to one user’s workflow)

  • In the configuration variable core.excludesfile – Patterns which a user wants GIT to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice). Note that you can set the global config value, so every single project you work on will always ignore those pesky files such as Thumbs.db.

There are also further technical details in which ignores take precedence etc. in case anyone wants some heavier reading:

Post a comment

All comments are held for moderation; Markdown and basic HTML formatting accepted.

(required)
(required, not published)
(optional)