Setting up Git LFS (Large File Storage) allows you to manage large files more efficiently by storing them outside your Git repository, reducing repo size and improving performance. Here’s how to set it up:
-
Download and Install Git LFS:
- For Windows or macOS: Download Git LFS from the official Git LFS website and run the installer.
- For Linux: Use a package manager:
sudo apt-get install git-lfs # Debian/Ubuntu
sudo dnf install git-lfs # Fedora
brew install git-lfs # macOS with Homebrew
-
Initialize Git LFS:
Run the following command to initialize Git LFS in your Git repository:
This command installs Git LFS hooks for your current repository. You only need to run this once per repo.
Specify which file types you want to store using Git LFS. For example, if you want to track .psd files:
This command will create or update a .gitattributes file in your repo, which tells Git LFS to track those file types.
Note: You can track multiple file types by running git lfs track for each file extension you need.
Now, add your files as usual, and Git will use LFS for the tracked file types:
git add .gitattributes # Stage the .gitattributes file if it’s new
git add path/to/large_file.psd
git commit -m "Add large file using Git LFS"
When pushing your changes, Git LFS will handle the large files separately:
To confirm that Git LFS is handling the large files, use:
- Configure Git LFS storage limits on your remote repository (e.g., GitHub, GitLab) to avoid storage cap issues.
- Manage tracked files by editing
.gitattributes if needed, and re-track files by updating your Git LFS configurations.
After these steps, Git LFS will manage the specified large files in your repository, optimizing your Git operations for large assets.