Skip to content

Instantly share code, notes, and snippets.

@benoit-dubreuil
Last active July 25, 2022 21:45
Show Gist options
  • Save benoit-dubreuil/4a262597e0d8a82d29b74e4507c470f3 to your computer and use it in GitHub Desktop.
Save benoit-dubreuil/4a262597e0d8a82d29b74e4507c470f3 to your computer and use it in GitHub Desktop.
Remove Git LFS from repo
#!/usr/bin/env bash
# See https://stackoverflow.com/a/35064134/2924010
# TODO : Rewrite history
# You must `cd` in your local repository beforehand.
LFS_FILES_EXTENSIONS="""*.7z
*.br
*.gz
*.tar
*.zip
*.pdf
*.gif
*.ico
*.jpg
*.pdf
*.png
*.tif
*.tiff
*.psd
*.webp
*.woff2
*.exe"""
while IFS="" read -r extension || [ -n "$extension" ]; do
git lfs untrack "*$extension"
done <<<"$LFS_FILES_EXTENSIONS"
git lfs uninstall
# WARNING! Disable this if you have custom hooks unrelated to Git LFS!
rm .git/hooks/pre-push
# WARNING! Disable this if you have custom behaviours unrelated to Git LFS in the file '.gitattributes'!
rm .gitattributes
while IFS="" read -r extension || [ -n "$extension" ]; do
git rm --cache "*$extension"
git add --force "*$extension"
done <<<"$LFS_FILES_EXTENSIONS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment