Search code examples
gitglob

Git path to match any directory name


In git we can use * to specify files name, like *.jpg, *.*, but how about directories?

Is there any method to specify all directory?

This doesn't work:

git rm firstdirectory/*/thirddirectory

The * doesn't do the "all directories" effect.


Solution

  • Your command doesn't work because you're specifying a directory to git. Your shell does the correct expansion, but in the end git receives git rm firstdirectory/somedir/thirddirectory, which git doesn't like (git rm expects files)

    To make your command work, use the -r flag, then git accepts directory:

    git rm -r firstdirectory/*/thirddirectory