To remove a large file from your repository, you must completely remove it from your local repository and from GitHub.
Warning: These procedures will permanently remove files from the repository on your computer and GitHub. If the file is important, make a local backup copy in a directory outside the repository.
Removing a file added in the most recent unpushed commit
If the file was added with your most recent commit, and you have not pushed to GitHub, you can delete the file and amend the commit:
Open TerminalTerminalGit Bash.
Change the current working directory to your local repository.
-
To remove the file, enter
git rm --cached:git rm --cached giant_file # Stage our giant file for removal, but leave it on disk
-
Commit this change using
--amend -CHEAD:git commit --amend -CHEAD # Amend the previous commit with your change # Simply making a new commit won't work, as you need # to remove the file from the unpushed history as well
-
Push your commits to GitHub:
git push # Push our rewritten, smaller commit
Removing a file added in an older commit
If the file was added in an earlier commit, you will need to remove it from your repository history. We suggest using a tool called The BFG:
bfg --strip-blobs-bigger-than 50M # Git history will be cleaned - files in your latest commit will *not* be touched
For more information, The BFG's documentation contains full download and usage instructions.

