1

So im currently working on a project and my my .env file is not greyed out (gitignore?). Trying to figure out what I need to do globally because I do have the file but my .env is never greyed out. Any suggestions? I can provide screenshots if needed.

I had someone do a a few commands in the terminal and was able to get my .env to go grey once. But I believe he told me he wasn't able to do it globally.

Reach out for help.

  • You can set up a machine-wide git excludes file. However you're better off just putting `.env` in the repo's gitignore file so it affects everyone working on that repo. – AKX Nov 25 '22 at 18:31

1 Answers1

0

First, make sure your .env is not already tracked (or any amount of .gitignore or core.excludesFile would not change anything)

cd /apth/to/.env
git rm --cached .env

Then check if it is currently ignored with:

git check-ignore -v -- .env
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks @VonC I ran git rm --cached .env and fatal: pathspec '.env' did not match any files showed up in my terminal. Then I ran this command git check-ignore -v -- .env Nothing showed up on the terminal as a response – LucasClay718 Dec 06 '22 at 18:48
  • Hi @VonC I added a .gitignore file inside of the project and included .env and now it is greyed out. However I am still curious why my gitignore_global does not recognize my .env file. I have it configured like this core.excludesfile=/Users/.gitignore_global – LucasClay718 Dec 06 '22 at 19:04
  • @LucasClay718 Try from your repository a `git config -l --show-origin --show-scope`: do you see your [`core.excludesFile`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-coreexcludesFile)? Does a `cat /Users/.gitignore_global` work? – VonC Dec 06 '22 at 20:10
  • Thank you. @Vonc when I ran git config -l --show-origin --show-scope this is what I was shown in my terminal core.excludesfile=/Users/ /.gitignore_global Not sure what you mean by does cat /Users/.gitignore_global work? Still very new to all of this. – LucasClay718 Dec 07 '22 at 03:03
  • @LucasClay718 I meant to type in a shell (What OS are you using by the way? What Git version?) the command `cat` followed by the path you see. Why a space in `/Users/ /.gitignore_global`? – VonC Dec 07 '22 at 06:36