How to remove permanently an object in GIT
April 14, 2017
· Admin
GIT
To remove permanantly an object in a remote GIT repository, simply perform these steps. Prior executing them, go to the GIT project folder. This is the one having the .git folder.
git filter-branch -f --index-filter "git rm -rf --cached \
--ignore-unmatch OBJECT-TO-DELETE" -- --all
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
git push --all --force
Replace OBJECT-TO-DELETE with the object to delete. For example, if you want to delete a complete folder called distributions located in the tools folder, replace OBJECT-TO-DELETE by tools/distributions The local copy of the modified repository cloned else where will have to be re-cloned. *** Keep a backup your repository before performing these operations ***.
Copyright 2012–2026, Claude "Tryphon" Théroux