# Versioning Assets with Git LFS

#### <mark style="color:blue;">Scenario</mark>

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.

***

<figure><img src="/files/Amz24P5iuOMoTzkIY75l" alt=""><figcaption></figcaption></figure>

### Setting up Git LFS Demonstrating how to set up Git LFS to track and manage large files in a repository.

Step 1: **Installing Git LFS**&#x20;

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**&#x20;

Once Git LFS is installed, navigate to your project's repository and initialise Git LFS by running the following command:

```bash
git lfs install
```

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**&#x20;

By default, Git LFS tracks files with certain extensions such as .png, .jpg, .mp4, etc.&#x20;

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:

```bash
*.jpg filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.mp4 filter=lfs diff=lfs merge=lfs -text
```

Step 4: **Committing and Pushing Changes**&#x20;

After configuring Git LFS, commit the `.gitattributes` file to your repository and push it to the remote repository:

```bash
git add .gitattributes
git commit -m "Configure Git LFS for large files"
git push origin <branch-name>
```

***

### **Best Practices for Using Git LFS in a Collaborative Environment**&#x20;

Discussing considerations and best practices for using Git LFS in a collaborative environment.

1. **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.
2. **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.
3. **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.
4. **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.

{% hint style="info" %}
Git LFS is a powerful tool that allows you to seamlessly version large files in your Git repositories, improving performance and collaboration.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gitdeveloperguide.solomonmarvel.com/git-in-real-world/git-in-real-world-practice-scenarios/versioning-assets-with-git-lfs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
