Little Git Tricks: Ignoring the .gitignore

The .gitignore file is a great help to ignore certain types of files (like *.exe or *.dll). A little entry in this file and you no longer need to remember only to check in the files you really need but not the other ones.

However, there are situations in which you need to add files that are excluded by a .gitignore entry. You can remove that entry, but then all the other files you don’t want to track are included.

A much simpler approach is to add a second .gitignore file in the folder where those needed *.dll files are located. You can add one entry with a ! at the beginning of the line to invert its meaning. Instead of don’t track it now means track those files:

This works well as long as you don’t clutter your project with .gitignore files. As soon as you start to add one .gitignore after another, you should stop and rethink your approach. As so often, the simplest approach isn’t necessarily the best one. It’s now time to talk with your team and start consolidating those different files in the .gitignore file located in the root folder of your repository. You can mix ignores and !ignores, but you should make sure that those are located next to each other.

This requires more collaboration and a few rules, but it will save you time in the long run.

1 thought on “Little Git Tricks: Ignoring the .gitignore”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.