Versioning Assets with Git LFS (Large File Storage)
Last updated
Last updated
Git Large File Storage (LFS) is an extension for Git that allows efficient versioning and management of large files in a Git repository. While Git is designed to handle text-based source code files efficiently, it can become slow and resource-intensive when dealing with large binary files, such as images, audio, video, or other design assets.
Git LFS solves this problem by storing the large files outside the Git repository, while still keeping track of their versions and metadata within Git. This approach allows developers to work with large files seamlessly, without compromising the performance of the Git workflow.
Step 1: Install Git LFS
Before using Git LFS, you need to install it on your local machine. Visit the official Git LFS website (https://git-lfs.github.com/) and follow the installation instructions for your operating system.
Step 2: Initialise Git LFS in a Repository
To start using Git LFS in a new or existing repository, navigate to the repository's root directory using the command line and run the following command:
This command initialises Git LFS in the repository and configures Git to use it for managing large files.
Step 3: Specify File Types to be Tracked by Git LFS
By default, Git LFS tracks files with specific extensions like .mp3
, .jpeg
, .psd
, etc. However, you can customise the file types that Git LFS should track in your repository. To do this, create a .gitattributes
file in the repository's root directory, and specify the file types to be tracked. For example:
This configuration tells Git LFS to track all files with the .psd
extension using the LFS storage.
Step 4: Stage and Commit Large Files
After setting up Git LFS, you can start adding large files to your repository. Use the git add
command to stage the files, and then commit them as you would with any other Git file. Git LFS will automatically handle the versioning and storage of the large files.
While Git LFS provides a solution for versioning large files, it's essential to be mindful of its limitations. Git LFS is optimised for files ranging from a few megabytes to a few gigabytes in size. Extremely large files may still pose challenges due to network and storage limitations. Consider using alternative solutions like cloud storage or content delivery networks for such cases.
When working with Git LFS, it's crucial to communicate with your team and establish guidelines for using LFS effectively. Ensure everyone on the team has Git LFS installed and follows the same file tracking conventions specified in the .gitattributes
file. Consistent usage of LFS ensures smooth collaboration and prevents issues with file versions.
When cloning a repository that uses Git LFS, the large files are not automatically downloaded. Instead, only the metadata and pointers to the large files are fetched initially. To download the actual file content, use the git lfs fetch
command after cloning the repository.
Git LFS tracks large files separately from regular Git files. To view the status of LFS-tracked files, use the git lfs ls-files
command. This command displays a list of files tracked by Git LFS along with their pointers and sizes.
If you have an existing Git repository with large files that you want to manage using Git LFS, you can migrate those files to LFS. The official Git LFS website provides detailed documentation on how to migrate existing repositories, including step-by-step instructions and best practices.
By using Git LFS, developers can effectively work with design assets, multimedia files, and other large binary files while still maintaining the benefits of Git's version control system. https://git-lfs.com