Skip to content

Instantly share code, notes, and snippets.

@cosemansp
Created March 27, 2015 15:49
Show Gist options
  • Save cosemansp/cece7ce163704c6f50dc to your computer and use it in GitHub Desktop.
Save cosemansp/cece7ce163704c6f50dc to your computer and use it in GitHub Desktop.
How to delete files permanently from your local and remote git repositories
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch FOLDERNAME" -- --all
Replace FOLDERNAME with the file or folder you wish to remove from the given git repository.
Once this is done run the following commands to clean up the local repository
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
Now push all the changes to the remote repository
git push --all --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment