Search code examples
gitignore

How do I get git to ignore files that have a certain extension but do not start with a certain prefix?


I have a folder of files, some of which begin with a certain prefix like "prefix_" and end with a specific extension, like ".txt".

How to I create an entry in .gitignore that will exclude all files that end with ".txt" but do not start with the prefix "prefix_"?

Thanks!


Solution

  • gitignore works from top to bottom. meaning, to do what you want, you have to set the more global rule at top but then add the exception in next lines. Like this:

    *.txt
    !prefix_*