I already had committed the folder before and want to remove the directory in the history as well.
I did the following:
Add folder to .gitignore
:
echo Folder_Name/ >> .gitignore
Remove from all commits:
git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch Folder_Name/' --prune-empty --tag-name-filter cat -- --all
remove the refs from the old commits:
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
Ensure all old refs are fully removed
rm -Rf .git/logs .git/refs/original
Perform a garbage collection
git gc --prune=all --aggressive
push you changes to the online repository:
git push
You are done here.
But you can to the following to push all the changes to all branches with: But be careful with this command!
git push origin --all --force
git push origin --tags --force
After that the folder was removed from git, but was not deleted from local disk.
Credits to comment https://stackoverflow.com/a/56140096/2521009