Git Large File Storage (LFS) is an extension for Git that allows you to efficiently handle large files and binary data within your repositories. This guide provides detailed steps on how to install Git LFS on an Ubuntu system, ensuring that you can manage large assets without overloading your repository's history.
What is Git LFS?
Git LFS replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub, GitLab, or Bitbucket.
Installing Git LFS on Ubuntu
Here’s a step-by-step guide on how to install Git LFS on an Ubuntu system.
Step 1: Install the necessary tools
Before installing Git LFS, ensure that Git is installed on your system. You can install Git using the following command:
sudo apt-get updatesudo apt-get install git
Step 2: Install Git LFS
Git LFS packages are included in the default repositories of newer versions of Ubuntu. You can install it directly using apt-get
:
sudo apt-get install git-lfs
Step 3: Initialize Git LFS
After installation, you need to set up Git LFS for your user account. This is done using the git lfs install
command:
git lfs install
This command needs to be run once per user account. It sets up the necessary hooks in your Git configuration that will allow LFS to manage large files.
Step 4: Configure Git LFS for a repository
Once Git LFS is installed and initialized, you can configure it to track large files within specific repositories. Navigate to your repository directory and specify the file types you want to track with Git LFS:
cd /path/to/your/repositorygit lfs track "*.psd"
Replace "*.psd"
with the appropriate file extension, for example, *.mp4
for video files or *.zip
for archives. This command adds the specified patterns to a .gitattributes
file in your repository.
Step 5: Add and commit changes
After setting up file tracking, make sure to add the .gitattributes
file and commit it:
git add .gitattributesgit commit -m "Configure Git LFS tracking"
Step 6: Continue using Git as usual
With Git LFS configured, you can continue to use Git commands as you normally would. Large files tracked by LFS will be handled automatically:
git add large_file.psdgit commit -m "Add a large Photoshop file"git push
When you push to a remote server, Git LFS will transfer the large files to the server's LFS cache, keeping your repository efficient and fast.
For further reading see the official Git LFS documentation.