Search code examples
gitgitignore

Git ignore except one file type


I have a rule that ignores bin folder (build results):
[Bb]in/

I want git to still add all .txt files, even those in bin directory (but ignore everything else in that dir). How can I achieve this?


Solution

  • [Bb]in/*
    !*.txt
    

    This pattern should find you an answer. If you prepend the negation(!) before a pattern, it is marked as not to be ignored irrespective of all the ignores above it. Refer - https://www.atlassian.com/git/tutorials/gitignore