Skip to content

Instantly share code, notes, and snippets.

@dchakro
Forked from everttrollip/remove-git-lfs.md
Last active June 10, 2021 09:10
Show Gist options
  • Save dchakro/f6db43cb362221eac34a3464129ad865 to your computer and use it in GitHub Desktop.
Save dchakro/f6db43cb362221eac34a3464129ad865 to your computer and use it in GitHub Desktop.
Removing git lfs from (any) repository

So, it has been an interesting journey, but time to remove git-lfs. Here follows a summary of the approach I used to safely remove git-lfs,

  • git add --update; git commit -m “Commit before lfs removal”; git push
  • git checkout -b “remove-lfs”
  • remove hooks git lfs uninstall
  • remove files enrolled in git-lfs from .gitattributes (open the file, delete the contents) [P.S. don’t delete the file!]
  • list all lfs files, git lfs ls-files
  • run git rm --cached for each file
    • git lfs ls-files | cut -f 3 -d ' ' | xargs git rm --cached
  • Untrack files (individually or pattern)git lfs untrack '*.xz'
  • run git add for each file individually
  • run a git status and make sure all the files were added properly
  • run git add --renormalize .
  • commit everything
git add .gitattributes
git commit -m "removed lfs"
git push
  • check that no lfs files left with git lfs ls-files
  • remove any items in lfs, rm -rf .git/lfs

Once your branch (fix/remove-lfs) is merged into develop, your team doesn't need to do anything other than simply pulling and checking out the new state of the world, their repository will work as-expected without git lfs installed. If git lfs is still installed, simply let them uninstall it: git lfs uninstall

Credits: Fedor, Taylor, Chase, Simon, Evert, Nuc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment