Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore file not ignoring .env.local or any other supposed private file

Tags:

gitignore

I encountered this error because I once mistakenly committed .env.local before adding it to .gitignore. The answer to it below.

like image 284
GeniusHawlah Avatar asked Oct 21 '25 11:10

GeniusHawlah


1 Answers

If you're facing something similar and you use the Git GUI in VSCode, just follow these steps:

  • Open your .env.local file or any file that's having this issue, copy the content to clipboard, and delete the file entirely.
  • Open your .gitignore file and delete the line that removes that file.
  • Commit your changes (not necessarily publish).
  • Now create a new .env.local file (or the file you deleted earlier in your case.)
  • Switch to your Source Control tab (where you see staged files), right click on this newly created file and add it to .gitignore

Now, it will be ignored for real.

like image 54
GeniusHawlah Avatar answered Oct 23 '25 07:10

GeniusHawlah