Skip to content

Instantly share code, notes, and snippets.

@eyedeekay
Created February 23, 2016 02:09
Show Gist options
  • Save eyedeekay/2bf919547b4161e27efe to your computer and use it in GitHub Desktop.
Save eyedeekay/2bf919547b4161e27efe to your computer and use it in GitHub Desktop.
Remove large files from git history automatically
#! /bin/sh
#This scipt searches for files larger than 100mb under the working directory and removes
#them from git automatically using git filter-branch. This makes it kind of dangerous,
#but also automatic and pretty useful.
WORKING_DIR=$(pwd)
for file in $(find "$WORKING_DIR" -size +100000000c -ls | grep -v ".git"); do
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch $file" HEAD
rm -rf .git/refs/original/ && git reflog expire --all && git gc --aggressive --prune
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment