My Actual Question
I would like that only the .gitignore
file in the root of my directory structure ignore files, i.e, the .gitignore
files in subdirectories shouldn't ignore files.
To be clear
I don't want to gitignore other .gitignore
files. I want them to be commited to git but I don't want them to gitignore other files.
Specific use-case
Let's say I want to commit a boilerplate project structure to git. Let's say the project structure looks like this:
project-root/
│
├── boilerplate/
│ ├──directory/
│ ├──some-other-directory/
│ ├──.env
└── └──.gitignore // Has a line ".env" which will ignore the .env file in this directory
│
├── boilerplate2/
│ ├──directory/
│ ├──some-other-directory/
│ ├──.env
└── └──.gitignore
│
└── .gitignore // The .gitignore in root
Now the .gitignore
file in boilerplate
directory will gitignore .env
which I don't want. How can I stop nested .gitignore
files from taking action?
What I tried?
I tried the negation (!
) operator in the main .gitignore
file. For the sample structure above, it's equivalent to !boilerplate/.env
. The .gitignore
in root simply doesn't have any power over the .gitignore
file in the specified directory. It doesn't override it. Why does it work like that? Is there a workaround?
Edit:
VonC suggests to automate that using scripts, but that's not the question. The question is, how to do that using only .gitignore
, if it is possible at all.