Jun 25, 2020
Per Djurner

Git ignore a folder with exceptions

Usually when working with .gitignore files it's pretty straight forward, you ignore some folders and / or files and you're done. But what if you want to ignore everything inside a folder except for specific folders and files inside it?

Here's how you can do that.

folder/*
!folder/tracked-folder
!folder/tracked-file.js

As you can see the ! prefix is used here. It negates the pattern so that any matching file excluded by a previous pattern will become included again.

Home