简体   繁体   English

如何在 github 中存储 .env 文件?

[英]How to store .env file in github?

I have a node.js project with .env file in it.我有一个带有.env文件的 node.js 项目。 I pushed to github project, when in .env file was just a template.我推送到 github 项目,当.env文件只是一个模板时。 For example:例如:

# Database credentials
DB_HOST=""
DB_USER=""
DB_PASSWORD=""
DB_DATABASE_NAME=""

Then I added .env file to .gitignore .然后我将.env文件添加到.gitignore Pushed again and now, when I filled .env file with credentials, git status command says一次又一次地推送,当我用凭据填充.env文件时, git status命令说

modifed: .env修改:.env

How can I store a template of .env file in github and ignore it's changes?如何在 github 中存储.env文件的模板并忽略它的更改?

When we need to provide templates for environment files or secrets, we tend to add a .sample to the file name.当我们需要为环境文件或机密提供模板时,我们倾向于在文件名中添加一个 .sample。 That's has been mine and my workplace convention, and a lot of people follows it.这是我和我的工作场所惯例,很多人都遵循它。 So you can have files like .env.sample and secrets.sample所以,你可以有一个像文件.env.samplesecrets.sample

您可以使用.env.example文件保存您的 env 模板,然后将其推送到 github,并将.env添加到.gitignore

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM