Frequently Asked Questions:
How can I remove/delete a large file from the commit history in the Git repository?
Use the BFG Repo-Cleaner, a simpler, faster alternative to git-filter-branch, specifically designed for removing unwanted files from Git history.
Carefully follow the usage instructions. The core part is just this:
java -jar bfg.jar --strip-blobs-bigger-than 100M my-repo.gitAny files over 100 MB in size (that aren’t in your latest commit) will be removed from your Git repository’s history. You can then use
git gcto clean away the dead data:git reflog expire --expire=now --all && git gc --prune=now --aggressiveAfter pruning, we can force push to the remote repo*
git push --forceNote: cannot force push a protect branch on GitHub
The BFG is typically at least 10-50 times faster than running
git-filter-branch, and generally easier to use.Full disclosure: I’m the author of the BFG Repo-Cleaner.
—Roberto Tyley (on StackOverflow)
How do I remove a submodule?
In modern Git (I’m writing this in 2022, with an updated
gitinstallation), this has become quite a bit simpler:Run
git rm <path-to-submodule>, and commit.This removes the filetree at
<path-to-submodule>, and the submodule’s entry in the.gitmodulesfile. I.e. all traces of the submodule in your repository proper are removed.As the docs note however, the
.gitdir of the submodule is kept around (in themodules/directory of the main project’s.gitdir), “to make it possible to checkout past commits without requiring fetching from another repository”.If you nonetheless want to remove this info, manually delete the submodule’s directory in
.git/modules/, and remove the submodule’s entry in the file.git/config. These steps can be automated using the commands:
rm -rf .git/modules/<path-to-submodule>git config --remove-section submodule.<path-to-submodule>—John Douthat (on StackOverflow)