I had tried multiple commands to delete a file entirely from the git and its history. Below is the version that worked without any issues. This requires force pushing the changes.
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch path-to-file-to-remove.txt" --prune-empty --tag-name-filter cat -- --all
If there is space in the path escape with a slash \
. After that force push to the repo.
git push -u origin main --force