Skip to content

Instantly share code, notes, and snippets.

@robandpdx
Last active March 14, 2023 15:58
Show Gist options
  • Save robandpdx/276a3f4d77f5a92c84562ab3f49051cd to your computer and use it in GitHub Desktop.
Save robandpdx/276a3f4d77f5a92c84562ab3f49051cd to your computer and use it in GitHub Desktop.

LFS Migration

A note about OS

By default, windows and mac do not have a case sensitive filesystem. For this reason, I recommend using linux for lfs migration. Also, if the lfs migration seems to take a long time, this is often due to lots of disk I/O. To speed things up, use a cloud linux instance with max disk I/O.

Before migrating to LFS

The first step in migrating to LFS is finding what needs to be migrated. Use git-sizer for this task. Here is a utility script that can be used to run git-sizer on all repos in an org.

Another great tool for understanding blob sizes in a repo is git filter-repo. See these instructions for gathering blob sizing with git filter-repo.

This would be a good time to perform any other repo cleanup needed, including removing sensitive data.

Also, make sure you have git-lfs installed.

Migrating to LFS

Once you have identified large files, migrate them to LFS as follows:

  1. Checkout all remote branches locally.
for REF in $(git for-each-ref --format='%(refname)' refs/remotes/origin/ | grep -v main | grep -v master | grep -v HEAD); do
    BRANCH_NAME=${REF#refs/remotes/origin/}
    git branch --track ${BRANCH_NAME} ${REF}
done
  1. Migrate to LFS, specifying the file extensions you want to migrate.
git lfs migrate import --object-map=./lfs-mapping.cvs --everything --include="*.[zZ][iI][pP],*[jJ][aA][rR],*.[dD][mM][gG]"
  1. Push all branches and tags
# Push all branches
for REF in $(git for-each-ref --format='%(refname)' refs/heads); do
    BRANCH_NAME=${REF#refs/heads/}
    git push -fu origin ${BRANCH_NAME}
done
# Push all tags
for REF in $(git for-each-ref --format='%(refname)' refs/tags); do
  TAG_NAME=${REF#refs/tags/}
  git push -fu origin "$REF":refs/tags/$TAG_NAME
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment