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.
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.
Once you have identified large files, migrate them to LFS as follows:
- 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
- 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]"
- 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