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 of the repository.
Removing a file that was added in an earlier commit
If you added a file in an earlier commit, you need to remove it from the repository's history. To remove files from the repository's history, you can use the BFG Repo-Cleaner or the git filter-branch command. For more information see "Removing sensitive data from a 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

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
