Skip to content

Instantly share code, notes, and snippets.

@schneefisch
Last active December 8, 2022 10:10
Show Gist options
  • Save schneefisch/a0da9bc4c6555f6b90425922501b6c75 to your computer and use it in GitHub Desktop.
Save schneefisch/a0da9bc4c6555f6b90425922501b6c75 to your computer and use it in GitHub Desktop.
Remove large objects from repository and history

Git remove large objects from history

check the size of the git repo

du -hs .git/objects/

delete file using git filter-branch

git filter-branch --index-filter 'git rm --cached --ignore-unmatch pathname'

e.g. removing ".ear" files

git filter-branch --index-filter 'git rm --cached --ignore-unmatch /deployments/application.ear' HEAD

cleanup backups

git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d

mark so that the garbage-cleaner does it's work

git reflog expire --expire=now --all
git gc --prune=now

force push to git repo

git push --all --force
git push --tags --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment