How to remove large files that you have wrongly committed in Git?

Sai Ankit
2 min readJun 17, 2020

--

GitHub has a cap on each file i.e 100 MB. BEWARE !

If you have mistakenly committed large files in your repository Git gives you an error, not allowing you to push the committed changes onto GitHub.

How to do you resolve this error ?

Simple solution is to remove those large files from he last commit and then force pushing onto GitHub without the large files. Yes, you are going to know how to do that in this reading.

Step #1 :

Make a note of the path of the large files that you have mistakenly committed in Git. The path of that large file / files is available on the error message that you have encountered when you tried to push with the large files.

Step #2:

Use this command in the terminal to remove commit of the large file.

git filter-branch --tree-filter 'rm -rf path/of/large/file' -f HEAD

Step #3:

If you find ‘No local changes to save’ on running this command you are good to go to Step #4.

git stash save

Step #4:

Now we will just force push the changes to our master branch

git push origin master --force

You would be still getting warnings. But there wouldn’t be any errors and other changes are successfully committed and pushed to GitHub.

If you don’t want this stuff to happen every time you

git add --all and git commit 

use anyone of the following :

  1. Git Large file storage — Git LFS to handle with large file committing
  2. Add those large files to .gitignore to never commit them.

Please do have a look into my YouTube channel: Code Studio Sai Ankit that discusses everything related to coding from Computer Science Concepts, Competitive Coding tutorials, Codeforces Editorials, Development Projects.
Please also do leave a like and Subscribe on the content you like 👍.

--

--