DEV Community

Cover image for .gitignore file IGNORED my .env file
Bhavya Kaushik
Bhavya Kaushik

Posted on

.gitignore file IGNORED my .env file

I'm learning React.

So while developing a project on React, I was using some Appwrite functionalities to do the backend stuff easily.

I created a .env file and saved all the necessary keys inside it.

I was about to commit the changes when I saw that the .env file was not showing in dark grayish color, instead showing greenish color in VSCode directory structure.

I understood that .gitignore file might not be considering .env file.

When I opened it, I saw that .gitignore does not have ".env" inside it. So, I wrote it. Then refreshed the directory but it was still showing the same result.

After researching, I found out that I need to delete the .env file and then commit it again.

So, this is how I solved this problem:

  1. Copied all the content of .env file in Clipboard and deleted .env file.

  2. Created a new .env file and pasted the copied content inside it.

  3. Updated .gitignore file by adding *.env inside it (Writing .env did not work for me).

  4. Committed the changes in git

git add .
git commit -m "Removing the .env file from git"
git push origin main

Top comments (2)

Collapse
 
remejuan profile image
Reme Le Hane

That’s because you’d already committed the file, gitignore only works on uncommitted files.

And easier approach would be to use git update-index —assume-unchanged .env command to forget the file, which will make the gitignore instruction work.

Collapse
 
bkaush profile image
Bhavya Kaushik

Thank you @remejuan for sharing this info😊