0

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 ?

Vampire
  • 35,631
  • 4
  • 76
  • 102

2 Answers2

0

You can just add .env line to your .gitignore, it will not be tracked in your repository after you save the changes.

If you have already committed .env, you can remove it using Git's CLI.

mimak
  • 211
  • 2
  • 9
0

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.

Vampire
  • 35,631
  • 4
  • 76
  • 102