Git Large File Storage (LFS) is an extension to Git that allows large files to be stored outside the main repository, thus reducing the size of the repository and improving performance. Here are the steps to configure a Git repository to use LFS:
Install Git LFS: First, you need to install Git LFS on your local machine. You can download and install Git LFS from the official website or by using a package manager like Homebrew or apt-get.
Initialize Git LFS: Once you have installed Git LFS, you need to initialize it for your repository. Run the following command in your repository’s root directory:
git lfs install
This command sets up Git LFS for your repository and modifies your Git configuration to enable LFS tracking.
Choose file types to track: By default, Git LFS tracks files with extensions like .jpg, .png, and .pdf. However, you can customize the file types that Git LFS tracks by creating a .gitattributes file in your repository’s root directory. For example, if you want to track files with a .psd extension, you can add the following line to your .gitattributes file:
*.psd filter=lfs diff=lfs merge=lfs -text
Track large files: Once you have configured Git LFS for your repository, you can start tracking large files by running the following command:
git lfs track "<pattern>"
Replace <pattern> with a file or a wildcard pattern that matches the files you want to track. For example, to track all .psd files, you can run:
git lfs track "*.psd"
Commit and push changes: After you have configured Git LFS and started tracking large files, you can commit and push your changes as usual. When you push changes that include large files, Git LFS will automatically upload the files to the LFS server and replace them with small text pointers in the main repository.
That’s it! Now your Git repository is configured to use Git LFS for large files. When you clone the repository on another machine, Git LFS will automatically download the large files from the LFS server and replace the text pointers with the original files.