I would like to share most simplest and easy to understand solution which worked for me.
First clone a fresh copy of your repo, using the --mirror flag:
git clone --mirror https://github.com/username/youproject.git
Then Download latest version of BFG jar file from https://rtyley.github.io/bfg-repo-cleaner/ rename it as bfg.jar and paste it inside YourRepoName.git folder.
Then run following lines in git bash.
java -jar bfg.jar --delete-files yourfilename
(only file name is needed, no need to mention path)
git reflog expire --expire=now --all && git gc --prune=now --aggressive
(it will strip out the unwanted dirty data which has been expelled out due to above command)
I faced issue here. My project was having open pull requests. If there are any open pull requests then you need to run this command
git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d
After this you can simply push master branch.
git push -u origin master
Its done. But remember to keep a copy in local of old repository before performing above action. All unmerged branches and open pull requests may get deleted.
I reduced my repo size from 40mb to 4mb by removing unwanted apk files which got pushed with my commits.