In this example, the entire structure of files and directories under the subdirectory deploy/linux/build/ needs to be entirely removed from the git repository.

Note:

  • FILTER_BRANCH_SQUELCH_WARNING=1 suppresses the warning about dangers of doing this
  • shopt -s globstar enables the recursive listing of files
shopt -s globstar # allows recursive listing of files
for f in deploy/linux/build/**/*; do \
  FILTER_BRANCH_SQUELCH_WARNING=1 \
  git filter-branch --index-filter \
    "git rm --ignore-unmatch -r --cached $f" \
    --prune-empty -f -- --all; \
done