$ git --version
git version 2.6.4
I realize this is a duplicate but the other question\'s answers have not helped.
Folder structure
The problem is simply because you are ignoring the directory dist
. So Git will no longer look into the directory to look for other files.
As explained in this related answer, you need to whitelist the directory and only ignore its contents. Since you are having a nested structure, this does end up being a bit complicated though:
# ignore everything in the `dist` folder
dist/*
# … but don’t ignore the `dist/samples` folder
!dist/samples/
# … but ignore everything inside that `dist/samples` folder
dist/samples/*
# … except the `README.md` there
!dist/samples/README.md
This is also explicitly mentioned in the gitignore documentation (emphasis mine):
An optional prefix "
!
" which negates the pattern; any matching file excluded by a previous pattern will become included again. It is not possible to re-include a file if a parent directory of that file is excluded. Git doesn’t list excluded directories for performance reasons, so any patterns on contained files have no effect, no matter where they are defined.