How to Ignore Files in Git Without .Gitignore

How to ignore files in Git without .gitignore

Git has a handy feature when it comes to preventing accidental file check-ins when the files are meant to stay local. The obvious candidates are compiled binaries when you only want to check in the source code. Other candidates are files with local configurations.

One can put all of those files and paths into a .gitignore file in the project. To persist those changes (and to share the common file contents with collaborators on the project), one usually adds the .gitignore file to Git like any other file in the project. Unfortunately, there are limits to this approach.

Putting local files into the .gitignore file only works well with items that are common for all collaborators, such as files and directories within the project. Just imagine what would happen if hundreds of collaborators put their specific paths into .gitignore. That practice would create a huge mess and churn.