Skip to content

Instantly share code, notes, and snippets.

@spikeheap
Last active December 31, 2015 17:19
Show Gist options
  • Select an option

  • Save spikeheap/8019649 to your computer and use it in GitHub Desktop.

Select an option

Save spikeheap/8019649 to your computer and use it in GitHub Desktop.
Script to purge large files from a git repository history
FILE_TO_DELETE="target"
# Filter the history
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ${FILE_TO_DELETE' --prune-empty --tag-name-filter cat -- --all
# Purge the local repository and force garbage collection
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
# Print new repository size
git count-objects -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment