The first step to find large files or add files by mistake
git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"
The second step, is removed from the warehouse in a file or folder
Deleted files, will be replaced bigfile above to find the file name
git filter-branch --force --index-filter \ 'git rm --cached --ignore-unmatch bigfile' \ --prune-empty --tag-name-filter cat -- --all
Delete a folder, find the wrongdir into the above folder
git filter-branch --force --index-filter \ 'git rm -r --cached --ignore-unmatch wrongdir' \ --prune-empty --tag-name-filter cat -- --all
The third step is to delete cached objects
You can skip this step, after confirming complete problem does not occur again until the execution (it can be said that these cached objects gives you a chance to undo the last operation).
git for-each-ref --format='delete %(refname)' refs/original | git update-ref --stdin git reflog expire --expire=now --all git gc --prune=now
The fourth step is to update the remote repository
(This step is executed, it really can not be saved. Please check backed up.)
git push --force --verbose --dry-run
git push --force