0

I have changes in my .env files and this include my database user name and password. I don't want to push (now and in the future) these changes because my colleagues are using different user/password and they will be affected if I do so - this is the current setup.

What am I gonna do so when I issue git status, modified: .env will not appear anymore but I have to keep my changes?

tatskie
  • 405
  • 1
  • 7
  • 16
  • Why don't you add .env file to .gitignore file? – Skywalker Jan 10 '18 at 02:49
  • 1
    `.env` shouldn't be in Git at all. It's `.gitignore`d [by default](https://github.com/laravel/laravel/blob/f4cba4f2b254456645036139129142df274a1ec1/.gitignore#L12). – ceejayoz Jan 10 '18 at 02:50
  • @Skywalker how to do that? it seemed to have no effect – tatskie Jan 10 '18 at 02:50
  • https://git-scm.com/docs/gitignore – Skywalker Jan 10 '18 at 02:51
  • @ceejayoz, i just said that's the current setup, I can't do anything about that. – tatskie Jan 10 '18 at 02:51
  • If its already in .gitignore file, then it won't get pushed to git. – Skywalker Jan 10 '18 at 02:53
  • @Skywalker, regardless of the status that says "modified"? other files listed in my gitignore do not behave this way when I edit them. – tatskie Jan 10 '18 at 02:55
  • That's weird. It shouldn't show that file in the list of modified files if the file is added in .gitignore file. Check again in the .gitignore file if you have added it correctly. – Skywalker Jan 10 '18 at 02:57
  • 3
    The gitignore has no effect on files already staged/commited. Remove the file from the repository. – tkausl Jan 10 '18 at 02:58
  • ifeego's answer at https://stackoverflow.com/questions/11451535/gitignore-is-not-working helped me out. – tatskie Jan 10 '18 at 03:39
  • 1
    Possible duplicate of [How to stop tracking and ignore changes to a file in Git?](https://stackoverflow.com/questions/936249/how-to-stop-tracking-and-ignore-changes-to-a-file-in-git) – 1615903 Jan 10 '18 at 06:32

1 Answers1

2

The problem is that it's already tracked (most likely).

You can remove it from the repository but keep your local copy by issuing the following:

git rm .env --cached

The --cached flag leaves it on your local machine, free to do what you like with it. The rm command will remove it from the repository tracker, however.

Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110