Ignore subdirectory's .gitignore
I’m creating my dotfiles and using oh my zsh. It creates a directory called .oh-my-zsh in my home directory.
I want to ignore everything inside .oh-my-zsh, except the custom/ directory. However, custom/ has the file example.zsh and a directory called example/, which contains the file example.plugin.zsh, and I also want to ignore them.
- Keep directory and all subdirectories recursively except files
- Why is .gitignore not ignoring my files?
- Git ignore except specific subdirectories
- .gitignore whitelisting vim folder
- git doesn't ignore 2 specifically named files
- How can I get the equivalent of .hgignore's regular expressions ^var/(?!\log|.dummy) and ^var/log/(?!\.dummy) in .gitignore?
To make it clearer, the structure can be thought as this:
.oh-my-zsh/ custom/ my-folder-to-be-kept/ .. example/ example.plugin.zsh example.zsh lib/ log/ ...
I have a .gitignore in my home directory:
/.oh-my-zsh/* !/.oh-my-zsh/custom/ /.oh-my-zsh/custom/example.zsh /.oh-my-zsh/custom/example/example.plugin.zsh
However, there’s a .gitignore file inside .oh-my-zsh, which contains the follow content:
locals.zsh log/.zsh_history projects.zsh custom/* !custom/example !custom/example.zsh *.swp !custom/example.zshcache cache/
When I add the untracked files, example.plugin.zsh is ignored, but example.zsh isn’t. Therefore, I think I’d have to ignore that .gitignore inside .oh-my-zsh so that my .gitignore can work, because
!custom/example.zsh is conflicting.
One Solution collect form web for “Ignore subdirectory's .gitignore”
Taken from the help of git
Patterns read from a .gitignore file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.
As your “sub .gitignore” file will override the .gitignore located in root your question should actually be
Can I make a .gitignore file to have no effect?
And the answer is no. There are ways to ignore a .gitignore file but this will only avoid the file to be commited while it will still be affecting what has to be ignored or not.
As a rule of thumb it is a bad habit to have multiple .gitignore within a project. In your case I would try to modify the content of the generated .gitignore to avoid the problem or directly the way it is generated. Your case sounds pretty strange and I think you are doing something wrong or that could be done better. You should maybe think about it again and restructure your concept. Any other solution will be just a work around