Search code examples
githubgitignore.env

How to ignore a file located in the same folder as .gitignore


My .env file is located in the same folder as my .gitignore file. Therefore, my .env file is not taken into account and is offered to me to be sent to git. How can I do?

image of my folder

How can i ignore my .env file ?


Solution

  • As your screenshot shows, your .env file is already tracked and has modifications. If a file is tracked, it is tracked, and .gitignore does not have any effect whatsoever.

    You can tell Git to assume the file being unchanged, but that is a very dangerous option, because then Git will happily overwrite it if you for example switch branches and the file is different between the branches and so on.

    If you do not want the file to be tracked, you need to unversion it, e.g. using git rm --cached .env. And to .gitignore you would add /.env to match only the filesystem entry on the same level.