Skip to content

Instantly share code, notes, and snippets.

@tamara-schmitz
Last active January 26, 2022 17:45
Show Gist options
  • Save tamara-schmitz/49893bcd1f857dfa664b286264be5883 to your computer and use it in GitHub Desktop.
Save tamara-schmitz/49893bcd1f857dfa664b286264be5883 to your computer and use it in GitHub Desktop.
Git LFS migration of a big repo

Make sure that you can run git lfs. If you cannot you are missing a dependency.

If you start a new repo all you need to do is to use git lfs track "*.zip" to mark future file types or directories. But this does not work if you want to migrate an existing repo. If your goal is to save space and make cloning faster, you need to rewrite the entire git history!

It is good to clone the entire repo in a separate folder, before pushing any of your changes.

Do not run git lfs track yet and if you have, remove any .gitattributes files that it has created.

Instead, start the migration like this:

git lfs migrate import --everything \
    --include="*.mp4,*.webm,*.mkv,*.flac,*.mp3,*.jpg,*.png,*.bmp,*.webp,*.ogg,*.gz,*.xz,*.bz2,*.zstd,*.7z,*.rar,*.zip,*.gpg,*.pdf,*.docx,*.doc,*.odt,*.xls,*.ods,*.pptx,*.odp"

Once completed, run git push --force to rewrite history!! muahahah!.

Ahem yeah if thinks go wrong, just force-push the old clone again.

Cleanup

Let's clean up. To remove unreferenced LFS objects from your local clone, run git lfs prune.

Cleaning up a remote repo is more tricky:

Resources

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