Search code examples
gitgitignore

override gitignore in subfolder


Consider the following file structure:

  • RootFolder

    • .gitignore
    • SubFolder
      • dist
      • .gitignore (it ignores the dist folder)

The .gitignore in the SubFolder is ignoring the dist folder. Is there any way I can include the dist folder by editing the .gitignore in the RootFolder?

I have like 20 SubFolders with the same .gitignore, it would be wonderful if I am able to do this, instead of going into each SubFolder and edit the gitignore manually to include the dist folders.


Solution

  • The .gitignore in the SubFolder is ignoring the dist folder. Is there any way I can include the dist folder by editing the .gitignore in the RootFolder?

    I misunderstoot that part first and thought it was the exact opposite. To answer this question: No, this won’t be possible.

    Gitignore files in subdirectories will always have a higher precedence over those in a parent directory. This is done to allow having generic rules in the root that can be overridden with more specific rules in a subdirectory.


    What you could do however is to simply get rid of all those .gitignore files in the subdirectories. Since you mentioned that they are all the same anyway, you could just remove them completely and put the still-relevant rules in the root’s .gitignore.