Git Large File Storage (LFS) is a Git extension designed for handling large files more efficiently. If you want to upload large files to a Git server or GitHub using Git LFS, follow these general steps:
Install Git LFS
$ curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
The above installation will go it as,
etected operating system as Ubuntu/bionic.
Checking for curl...
Detected curl...
Checking for gpg...
Detected gpg...
Detected apt version as 1.6.14
Running apt-get update... done.
Installing apt-transport-https... done.
Installing /etc/apt/sources.list.d/github_git-lfs.list...done.
Importing packagecloud gpg key... gpg: WARNING: unsafe ownership on homedir '/home/hf/.gnupg'
Packagecloud gpg key imported to /etc/apt/keyrings/github_git-lfs-archive-keyring.gpg
done.
Running apt-get update... done.
The repository is setup! You can now install packages.
Now, we can install the git lfs as
$ sudo apt-get install git-lfs
Initialise Git LFS
Run the following command in your Git repository to initialize Git LFS,
$ git lfs install
The above command should show “Git LFS initialized.”
Now, we can check the version of installaed git lfs as,
$ git lfs version
git-lfs/3.2.0 (GitHub; linux amd64; go 1.18.2)
Now, once we have git lfs installed, use the below command to add the files,
Track Files with LFS
Identify the large files you want to track with Git LFS. Use the git lfs track
command to specify which file types should be treated as large files
$ git lfs track "*.psd"
This will add all the files with extention “.psd” into the git tracking and crate a file which then git uses to push those to server.
Add and Commit Changes
Add and commit your changes as you normally would with Git.
$ git add .
$ git commit -m "Add large files tracked with LFS"
Push to Remote
Push your changes to the remote repository. Git LFS will automatically upload the large files to the LFS server.
$ git push origin branch-name
Replace branch-name
with the name of your Git branch.
Verify on GitHub
Go to your GitHub repository and check the “Actions” tab to ensure that the Git LFS files are being uploaded successfully