5

I'm doing a project in JavaScript (React / Node) and I want to ignore every .env files in it,

I don't only have one .env file at the root of the project, because I have a folder for the front-end and another for the back-end,

Root
  backend
    .env
  frontend
    .env
  .gitignore

And in the .gitignore file :

/node_modules
/backend/node_modules
/frontend/node_modules
/backend/.env
/frontend/.env

node_modules folders are ignored but not the env files,

The gitignore file is at the root, but should I have a gitignore file in every folder ?...

VersifiXion
  • 2,152
  • 5
  • 22
  • 40

2 Answers2

11

Solution:

**/.env

Explanation:

A leading "**" followed by a slash means match in all directories. For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo". "**/foo/bar" matches file or directory "bar" anywhere that is directly under directory "foo".

https://git-scm.com/docs/gitignore

wotanii
  • 2,470
  • 20
  • 38
0

You can ignore by adding * before the file extension. inside .gitignore add like backend/*.env For more generic you can do like **/*.env

Rajesh Kumaran
  • 201
  • 1
  • 8