MANAGING LARGE FILES WITH GIT LFS

Git LFS is an open source git extension that enables statically storing of large files to a remote server. On your git repository only a few kilobytes text files is stored.

MANAGING LARGE FILES WITH GIT LFS
GIT LFS

Working with git has always been great, but not without shortcomings. Especially when it comes to dealing with large files such as videos, audio, binaries, or other huge datasets. The rule has always been don't keep files larger than 1 GB.

Git LFS is an open-source git extension that enables the statically storing of large files to a remote server. On your git repository, only a few kilobytes of text files are stored. The text files each contain a pointer to where the file is stored in the remote server. The files can be stored on a remote server on either GitLab or GitHub, as both support LFS.

GETTING STARTED WITH GIT LFS

There are several ways to install git LFS. For instance, on Debian, you can install git lfs like this sudo apt-get install git-lfs the binary method where you install the binaries. The command may vary depending on your Linux flavor. i.e Fedora sudo dnf install git-lfs

For this tutorial, however, we'll focus on the Git way of installing the Git LFS extension. To install run the below command.

 git lfs install  

Install Git LFS

If you have an existing git repository I recommend rewriting your history so the files are converted to LFS.

Example

  git lfs migrate import --include="*.db" 

Example command migrating all .db to be stored as LFS

The above command rewrites your history to use LFS, making your git repository smaller. In this case, we are rewriting all .db files.

You can then track the files

git lfs track "*.db"

Track .db

Ensure .gitattributes are tracked.

git add .gitattributes

track attributes

You can then commit and push the changes.

git add .
git commit -m "Working with LFS"
git push origin main

Commit and push

PULLING LFS FILES

Since LFS files are stored statically on a remote server, when you clone your git repository the actual files will not be there. Just the text files each containing a pointer to the actual file.

To get the actual LFS file run the below command.

git lfs pull

To get the latest text files with pointers run the below command.

git lfs fetch --all

Conclusion

Git LFS truly has made working with large files easier on Git. It's my hope in the future it gets integrated into git and not as an extension.

Subscribe to Bluedoa Digest

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
alexander@example.com
Subscribe