Skip to content

Instantly share code, notes, and snippets.

@luffy-yu
Last active November 18, 2021 23:19
Show Gist options
  • Save luffy-yu/26fd49069ee484bf8c1bdbfdbbce28bb to your computer and use it in GitHub Desktop.
Save luffy-yu/26fd49069ee484bf8c1bdbfdbbce28bb to your computer and use it in GitHub Desktop.
Git LFS Best Practice

Tip: Git LFS space is limited, so please use it to manager REAL large files whose size is greater than 100MB.

Reading the official tutorial first

Git-LFS Tutorial

For an empty project

# init git
git init

# init lfs
git lfs install

# track specific file types
git lfs track *.fbx
git lfs track *.mp4

# lookup what types are tracked
git lfs track

# add .gitattributes file first
git add .gitattributes

# add other files
git add .

# commit 
git commit -m "this is the commit message"

# push
git push -u origin master

# Just in case, run the following and run `git push -u origin master` again
git lfs push origin master --all

For an existing project

For new files

Same as For an empty project

For those files already added in git

git lfs migrate import --include="*.fbx" --include-ref=refs/heads/master 

Remove file in git history

git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD

Only track big files

Not working, I don't know why.

# track files which are greater than 100MB
find * -type f -size +100M -exec git lfs track --filename '{}' +

# add files which are greater than 100MB
find * -type f -size +100M -exec git add '{}' +

I researched and found that maybe git lfs did not support track specific files expected files like Assets/Model/*.fbx.

Fetch LFS objects after checkout or clone

# download
git lfs fetch

# revert to original file type
git lfs checkout

Uninstall Git LFS for some repo

Refer

One more thing

Git LFS tips and tricks

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