Versioning Assets with Git LFS
Last updated
Last updated
Scenario and Motivation Illustrating a scenario where a project involves versioning large files such as design assets.
In this scenario, let's consider a web development project where you need to include high-resolution images, videos, and other design assets. These files are an integral part of the project, and you want to keep track of their changes over time. However, including them directly in the Git repository would result in a significantly large repository size, making cloning, pushing, and pulling slow and inefficient.
Step 1: Installing Git LFS
Before getting started, you need to install Git LFS on your system. Refer to the Git LFS documentation for installation instructions specific to your operating system.
Step 2: Initialising Git LFS in the Repository
Once Git LFS is installed, navigate to your project's repository and initialise Git LFS by running the following command:
This command sets up Git LFS globally on your system and prepares the repository for tracking large files.
Step 3: Configuring File Types to be Tracked by Git LFS
By default, Git LFS tracks files with certain extensions such as .png, .jpg, .mp4, etc.
However, you can customize which file types are tracked by creating a .gitattributes
file in the repository's root directory. Open the .gitattributes
file and add patterns for the file types you want to track using Git LFS. For example:
Step 4: Committing and Pushing Changes
After configuring Git LFS, commit the .gitattributes
file to your repository and push it to the remote repository:
Discussing considerations and best practices for using Git LFS in a collaborative environment.
Educate Team Members: Ensure that all team members are aware of Git LFS and understand its usage. Share the setup instructions and best practices to avoid any confusion or mistakes.
Git LFS Pointer Files: Git LFS uses pointer files to track large files, while the actual file content is stored on a Git LFS server. It's essential to treat these pointer files like regular Git files and include them in commits and pull requests.
Ignore Local LFS Cache: Add the LFS cache directory (/.git/lfs/objects
) to your repository's .gitignore
file to prevent accidentally committing the LFS cache.
Use Git LFS Locking: In a collaborative environment, it's important to prevent conflicts when multiple team members are working on the same large file simultaneously. Git LFS provides a locking mechanism to ensure exclusive access to a file during editing. Utilise this feature when required to avoid conflicts.
Git LFS is a powerful tool that allows you to seamlessly version large files in your Git repositories, improving performance and collaboration.