How to use Git Large File Storage (git-lfs)

While working on updating my website recently I noticed this message when doing a “git push”.
> git push
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (20/20), done.
Writing objects: 100% (20/20), 92.49 MiB | 1.10 MiB/s, done.
Total 20 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), completed with 5 local objects.
remote: warning: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
remote: warning: See http://git.io/iEPt8g for more information.
remote: warning: File includes/images/computers/builds/2004/VID_20170918_174906.mp4 is 67.53 MB; this is larger than GitHub's recommended maximum file size of 50.00 MB
To github.com:dsdickinson/codeuniversity.git
4c8f617..1f2b31a master -> master

 

I knew this would be a concern but hadn’t had to address it as of yet. So I decided to do some research on git-lfs to get familiar with it. These links were helpful:
https://git-lfs.github.com
https://www.youtube.com/watch?v=uLR1RNqJ1Mw
https://help.github.com/en/github/managing-large-files/versioning-large-files

Installation
> brew install git-lfs
...
Update your git config to finish installation:

# Update global git config
$ git lfs install

# Update system git config
$ git lfs install --system

Post Install
Make sure at this point you are in the repo you intend to use git-lfs in. This part you will have to do in all applicable repos it will be used in.
> git lfs install
Updated git hooks.
Git LFS initialized.

Specify file types to track.
> git lfs track "*.mp4"
Tracking "*.mp4"

Check file types being tracked.
> git lfs track
Listing tracked patterns
*.mp4 (.gitattributes)
Listing excluded patterns

Now at this point even though I had some *mp4 files added and committed to my repo already, it found these same files and changed them to use the new git-lfs module.

> git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

modified: includes/images/computers/builds/2004/VID_20170918_174906.mp4
modified: includes/images/computers/builds/2018/VID-20180201-WA0001.mp4
modified: includes/images/computers/builds/2018/VID_20180121_145056.mp4
modified: includes/images/computers/builds/2018/VID_20180125_204256.mp4

So I then added them, committed them and pushed them up again.
> git add includes/images/computers/builds/2004/VID_20170918_174906.mp4
> git add includes/images/computers/builds/2018/VID-20180201-WA0001.mp4
> git add includes/images/computers/builds/2018/VID_20180121_145056.mp4
> git add includes/images/computers/builds/2018/VID_20180125_204256.mp4

> git commit
[master 6fbfa4b] Added mp4 files to git lfs.
4 files changed, 0 insertions(+), 0 deletions(-)
rewrite includes/images/computers/builds/2004/VID_20170918_174906.mp4 (99%)
rewrite includes/images/computers/builds/2018/VID-20180201-WA0001.mp4 (100%)
rewrite includes/images/computers/builds/2018/VID_20180121_145056.mp4 (99%)
rewrite includes/images/computers/builds/2018/VID_20180125_204256.mp4 (99%)

> git push
Uploading LFS objects: 100% (4/4), 113 MB | 1.3 MB/s, done.
Counting objects: 12, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 1.29 KiB | 1.29 MiB/s, done.
Total 12 (delta 4), reused 0 (delta 0)
remote: Resolving deltas: 100% (4/4), completed with 4 local objects.
To github.com:dsdickinson/codeuniversity.git
1f2b31a..6fbfa4b master -> master

So the git-lfs module simply creates link references in my main repo on github.com to the new files in GitHub’s git-lfs server.

Here is how you can view the files that are being managed with git-lfs.

> git lfs ls-files
60c5be30ad * includes/images/computers/builds/2004/VID_20170918_174906.mp4
952f1a8feb * includes/images/computers/builds/2018/VID-20180201-WA0001.mp4
1a94475aa5 * includes/images/computers/builds/2018/VID_20180121_145056.mp4
4e3656ea95 * includes/images/computers/builds/2018/VID_20180125_204256.mp4

That’s pretty much all there is to it. Everything else in your GitHub workflow is the same.

Leave a comment