DEV Community

Discussion on: Please don't commit .env

Collapse
 
bgadrian profile image
Adrian B.G. • Edited
  1. Install the operating system
  2. edit your user global gitignore vim ~/.gitignore
  3. paste:
.idea/
.vs/
.env
.pk
.pem
.pub
Enter fullscreen mode Exit fullscreen mode

Do not think you will not make a mistake, be proactive and presume you will, we are only humans.

Edit: this will prevent adding to your project your IDE config files, environment and private keys

Collapse
 
emmanuelnk profile image
Emmanuel K

Best and most useful solution. prevention before cure.

Collapse
 
codemouse92 profile image
Jason C. McDonald

Awesome, just did this in all my repos.

Collapse
 
somedood profile image
Basti Ortiz

We're glad to hear that!

Cheers! ๐Ÿฅ‚ *clink*

Collapse
 
nickjj profile image
Nick Janetakis • Edited

That's pretty dangerous advice because it depends on how you configure your application.

I personally commit .env files because they don't contain sensitive information and typically having settings important to being able to start up my app in development. I have a feeling just about anyone using Docker Compose would also commit .env files too since it's used for setting your project name.

I reserve .env.prod or other environment specific files for sensitive API keys and other things I wouldn't want to commit.

Collapse
 
bgadrian profile image
Adrian B.G.

It is not dangerous and also .env.prod is very specific.

You can always commit the files from gitignore, but you have to do it explicitly, so you avoid mistakes --force.

Thread Thread
 
nickjj profile image
Nick Janetakis • Edited

I just mean putting it into your main .gitignore file is dangerous because you run the risk of not committing essential settings to make your project work if it depends on .env being around.

Using --force every time they want to add a file isn't a viable solution IMO. That's a command you might run 50 times a day.

In other words, you should add .env on a per project basis when your project may have .env files that contain sensitive info, just like you would want to ignore any other files that have sensitive data.

Collapse
 
snowe2010 profile image
Tyler Thrailkill

You shouldn't ignore the idea folder. you're supposed to commit almost all of it to the repo.

intellij-support.jetbrains.com/hc/...
rider-support.jetbrains.com/hc/en-...

Collapse
 
bgadrian profile image
Adrian B.G.

Nope, thats what they say but is it a bad practice.

Each env had its own tweaks and sometimes diffenrent platforms, tasks, settings and folders. Each dev should have the liberty of using its own IDE in their own productive way.

Thread Thread
 
snowe2010 profile image
Tyler Thrailkill

Ah yes, let's not use the tool as instructed. That will go great.

Each env had its own tweaks and sometimes diffenrent platforms, tasks, settings and folders. Each dev should have the liberty of using its own IDE in their own productive way.

Yeah, and they tell you exactly which things to exclude in order to get that.

You should include the idea folder. End of story.

Thread Thread
 
bgadrian profile image
Adrian B.G.

No, sorry.

Do some research on the topic you will see that many other developers share my opinion. Do not blindly trust the IDE creators, for them is a business, for you is just a tool.

IDE's are local tools, they are not related to the project. A big project then will have

.vim
.idea
.eclipse
.atom
.vscode

folders. Where did you saw that?

You can also browse popular open source projects source code and see that most of them do not have IDE config files.

Thread Thread
 
dietergeerts profile image
Dieter Geerts

That's because devs want "clean" repos, but there is a JetBrains template, which will ignore USER settings, but you should still commit PROJECT setttings, as not all settings can be read from .editorconfig or linting etc.... This will help other devs that uses that IDE to not waste time on configuring the IDE to get auto-format correct etc... Also VSCode has files that should be committed.