Prometheus
Prometheus

Reputation: 33625

Git ignoring a file but not ones with names

In my .gitignore file I want to ignore a file just called .env but not files that have something.env:

I have tried this:

.env
!*.env

But it does not work

Upvotes: 1

Views: 2249

Answers (2)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476659

Why can't you simply ignore .env. Thus your .gitignore reads:

.env

(only one line)

It will not ignore anything with the .env extension.

Example (console):

$ echo 'foo' > .env
$ echo 'foobar' > foo.env
$ git add .; git commit -am "foobar"
[master 49d6a00] foobar
 2 files changed, 2 insertions(+), 2 deletions(-)
 create mode 100644 foo.env

Upvotes: 2

pratZ
pratZ

Reputation: 3346

Just add .env in your .gitignore file

.gitignore

.env

Upvotes: 4

Related Questions