Search code examples
gitgitignore

gitignore - is there any difference between !/**/ and !*/


I was going through the answers of How do I add files without dots in them (all extension-less files) to the gitignore file?

One answer is:

*
!/**/
!*.*

and the other answer is:

*
!*/
!*.*

So, is there any difference between !/**/ and !*/ or are they similar.


Solution

  • Since I wrote the original answer (in 2013), I believe my intent was to anchor the exclusion at the top folder '/' (where the .gitignore is), with the special format:

    A trailing "/**" matches everything inside. For example, "abc/**" matches all files inside directory "abc", relative to the location of the .gitignore file, with infinite depth.

    Meaning I want to exclude all folders (**/) starting from the top (/: inside top folder).

    That is a more complex way to write */ with:

    • '*': match anything (except '/') at any depth
    • '/': match only folders (which ends with '/')

    In both instances, the idea remains:

    • ignore everything
    • except folders
    • then except dot files