Skip to content

Instantly share code, notes, and snippets.

@cakriwut
Created August 22, 2016 23:50
Show Gist options
  • Save cakriwut/ac240087689e4831edd90ef28a893bb2 to your computer and use it in GitHub Desktop.
Save cakriwut/ac240087689e4831edd90ef28a893bb2 to your computer and use it in GitHub Desktop.
Remove file/folder from GIT repo permanently
REM Remove folder Sample/packages from GIT repository
git --filter-branch --index-filter "git rm --cached --ignore-unmatch -rf Sample/package" --prune-empty --tag-name-filter cat -- --all
REM Remove file Sample/packages/filetoremove.txt from GIT repository
git --filter-branch --index-filter "git rm --cached --ignore-unmatch Sample/package/filetoremove.txt" --prune-empty --tag-name-filter cat -- --all
REM push the result to origin
git push origin --force --all
git push origin --force --tags
REM cleanup - if everything OK
git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment