Does subdirectory gitignore override parent directory gitignore?
Yes, it does.
- I was in root directory while executing steps below.
- Root directory
.gitignorewas empty.
Observation 1:
Adding file to gitignore after staging it, will not remove it from staging.
Steps I did to test this:
- Create empty .gitignore
- Create env file
- Run
git add . - env file will be staged
- set gitignore to look like this
.gitignorein this repository - Run
git status - env file will be still staged
Steps that prove subdirectory gitignore overrides parent one:
- Create empty .gitignore
- Add files to be gitignored
- Run
git add - Run
git status - Gitignored file in subdirectory wont be staged
This will allow me to have many subdirectories containing their own gitignore which is important to me because of node_modules.