Mastering git, Part 14, Git Large File Storage

Git Large File Storage LFS

Git LFS is an extension for Git that allows you to efficiently manage large files and binary files in a Git repository.

Install Git LFS

Ensure Git LFS is installed, you can check by running:

Initialize Git LFS in Your Repository

After installing Git LFS, navigate to your Git repository and initialize Git LFS:

This command needs to be run once per repository to set up the necessary hooks.

Track Large Files with Git LFS

For example, to track all .psd files, you would use:

or add a path:

To track files of a specific type within a directory and its subdirectories (a nested directory structure), use the ** wildcard. For instance, to track all .bin files in assets/ and any of its subdirectories, you would use:

The command modifies the .gitattributes  file, telling Git to use LFS for these files.

Add and Commit Files as Usual

After you’ve set up tracking, you can add and commit files as you normally would:

Git LFS automatically replaces large files with pointers in the Git repository, while the actual files are stored in a separate LFS cache.

After running the git lfs track command for your specific path or directory, Git LFS will modify the g.gitattributes file in your repository to include the new tracking paths. Make sure to commit changes to the g.gitattributes file.

Cloning and Pulling from a Repository with LFS Files

When cloning or pulling from a repository that uses Git LFS, the LFS files are automatically downloaded.

Listing Tracked Large Files

 

This command lists the files currently tracked by Git LFS in your repository, along with their sizes and the SHA-256 hashes of the versions of those files that are checked out in your working copy.

You can also manually inspect the .gitattributes file in your repository’s root directory. This file contains the patterns for files tracked by Git LFS. For example, you might see lines like:

Cloning a Repository with LFS Files

When you clone a repository that uses Git LFS, If Git LFS is installed, LFS-tracked files should be automatically downloaded when you clone the repository. However, if this does not happen, you might need to manually fetch the LFS files:

git lfs fetch: downloads the LFS files for your current branch from the remote.
git lfs checkout: replaces the placeholder pointers in your working directory with the actual large files.

 

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x