2

I have a node.js project with .env file in it. I pushed to github project, when in .env file was just a template. For example:

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

Then I added .env file to .gitignore. Pushed again and now, when I filled .env file with credentials, git status command says

modifed: .env

How can I store a template of .env file in github and ignore it's changes?

Don2Quixote
  • 228
  • 2
  • 12
  • If you commit a file once and then add it to gitignore, git will continue tracking it. [check this answer](https://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files) – Shriram Jun 22 '22 at 14:36

2 Answers2

4

When we need to provide templates for environment files or secrets, we tend to add a .sample to the file name. 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

Faizaan Khan
  • 1,733
  • 1
  • 15
  • 25
  • 1
    In this case my code's users will must to do more actions: rename `.env.sample` to `.env`, fill it and only then start – Don2Quixote Oct 01 '20 at 19:06
1

you can save your env template using .env.example file then push it to github, and add .env to .gitignore

Andy Winarko
  • 645
  • 1
  • 9
  • 20