1

I have added .env name in ignorance file but it's not working. Please guide me.

My git-ignore:

node_modules/
npm-debug.log

bootstrap/compiled.php, 
app/storage/, 

public/storage, 
public/hot, 
storage/*, 
storage/*.key, 
.env.*.php, 
.env.php, 
.env, 
Homestead.yaml, 
Homestead.json

My git-ignore.save:

public/storage, 
public/hot, 
storage/*.key, 
storage/upload, 
storage/exports, 
storage/files/* , 
.env.*.php, 
.env.php, 
.env, 
Homestead.yaml, 
Homestead.json, 
storage/uploads, 
ven
phd
  • 82,685
  • 13
  • 120
  • 165

5 Answers5

4

Your file is not being ignored because you previously told git to follow the file with git add, delete the file using git rm -f .env, and push the deletion, so it's fully ignored

Ferrybig
  • 18,194
  • 6
  • 57
  • 79
2

Try this:

Make sure your git ignore file name is ".gitignore"

First delete .env file and put .env in your .gitignore file then push to your git repository

After pushed to your repository then add .env file to your project directory.

It will solved your problem.

Sahil Darji
  • 224
  • 1
  • 6
2

If your .env file is not getting ignored even after adding in .ignore than run below command in your terminal.

git update-index --assume-unchanged .env

And if you feel later that you want to make some changes again in the .env file then run below command:

git update-index --no-assume-unchanged .env

NOTE: In case of any other file replace .env with that filename(along with proper path)

Nikhil G
  • 2,096
  • 14
  • 18
1

This is the solution that always works for me

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

This is from stackoverflow .gitignore is ignored by Git

Marcus
  • 1,850
  • 1
  • 12
  • 24
0

In your gitignore file, add an asterisk in front of the .env: *.env

Andrew H
  • 35
  • 1
  • 6