Using Git LFS with GitLab

A guide to enabling Git LFS in a GitLab repository and adding files.

Git LFS

This guide explains how to enable Git Large File Storage (LFS) in a GitLab repository, specifically for the project that can be cloned using the URL git@gitlab.com:c2platform/phx/examples/git-lfs-and-gitlab-pages.git.

Step 1: Install Git LFS

Before you can use Git LFS, you need to install it. Follow the installation instructions for your operating system from the Git LFS website.

Step 2: Clone Your Repository

Clone your repository:

git clone git@gitlab.com:c2platform/phx/examples/git-lfs-and-gitlab-pages.git
cd git-lfs-and-gitlab-pages

Step 3: Enable Git LFS

Enable Git LFS in your repository:

git lfs install
git lfs track "*.tar.gz"

Note

The second/track command creates a file .gitattributes with contents

*.tar.gz filter=lfs diff=lfs merge=lfs -text
Show me
(c2d) ostraaten@mpc2:~/git/gitlab/c2/phx/examples/git-lfs-and-gitlab-pages$ git lfs install
Updated Git hooks.
Git LFS initialized.
(c2d) ostraaten@mpc2:~/git/gitlab/c2/phx/examples/git-lfs-and-gitlab-pages$ git lfs track "*.tar.gz"
Tracking "*.tar.gz"
(c2d) ostraaten@mpc2:~/git/gitlab/c2/phx/examples/git-lfs-and-gitlab-pages$ cat .gitattributes
*.tar.gz filter=lfs diff=lfs merge=lfs -text

Step 4: Add Your Large File

Add your large file, for instance:

wget https://archive.apache.org/dist/tomcat/tomcat-10/v10.1.23/bin/apache-tomcat-10.1.23.tar.gz
git add .gitattributes apache-tomcat-10.1.19.tar.gz

Step 5: Commit and Push Your Changes

Commit and push your changes:

git commit -m "Add Apache Tomcat tar.gz file with LFS"
git push origin main

Verification

To verify that the file is being handled correctly by Git LFS, you can run:

git lfs ls-files
Show me
(c2d) ostraaten@mpc2:~/git/gitlab/c2/phx/examples/git-lfs-and-gitlab-pages$ git lfs ls-files
c3ea69d92b * apache-tomcat-10.1.19.tar.gz

This command will display a list of files tracked by Git LFS in your repository.

By following these steps, you can efficiently manage large files using Git LFS in your GitLab repository.