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.

To make it clearer, the structure can be thought as this:


I have a .gitignore in my home directory:


However, there’s a .gitignore file inside .oh-my-zsh, which contains the follow content:


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.

  • Git: how to ignore hidden directories?
  • Git dealing with large amounts of files which shouldn't be checked into svn
  • .gitignore does not understand my folder wildcard on windows
  • Is there a way to tell git to only include certain files instead of ignoring certain files?
  • Git ignore files matching a pattern only
  • Recommended .gitignore file for Python projects?
  • Git: ignore files but not sub-directories in a directory
  • files from folder excluded in .gitignore appears in commits
  • 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

    Git Baby is a git and github fan, let's start git clone.