Search code examples
gitgitignore

How to ignore exact filenames in .gitignore? (without substrings)


Lets say that I have a file which contains sensitive information called secrets/passwords.txt. I want git to ignore this file, but upload another file named /secrets/passwords.txt.template which contains that key names without the passwords themselves.

How can I write a logic in .gitignore that ignores secrets/passwords.txt, but includes secrets/passwords.txt.template?


Solution

  • Just add the file you want to ignore, like:

    secrets/passwords.txt
    

    Note, that in order to explicitly negate ignoring (which should not be necessary in your case), you can use ! prefix, like:

    !secrets/passwords.txt.template  //! will negate the instruction