Completely Remove Pushed Files and/or Folders from Git Repository

Here’s the recipe to remove the lib folder. You can change the file/path matching and also limit the command for range of commits because what it actually does is basically overwriting the history and removing the unwanted files.

Step 1: filter-branch

git filter-branch --index-filter 'git rm --cached --ignore-unmatch lib/*' --tag-name-filter cat -- --all

Step 2: push –force

git push --force

This will clean the unwanted lib folder from the repository completely

It will not rewrite the log commits though and the commit messages will still be there.

[This is an update to post on how to remove Pods folder from iOS project]