Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Getting Started with LFS in GitLab

This post is still in progress.

After having set up GitLab with LFS, I needed to install an LFS client in order to make use of it in my repository. On Ubuntu 18.04, this was as easy as running:

sudo apt-get install git-lfs -y
git clone ssh://git@gitlab.secureapphost.com:23825/diverse-interactive/clients.diverseinteractive.com.git
cd clients.diverseinteractive.com
git lfs install

You should see:

Updated git hooks.
Git LFS initialized.

To add items to be tracked by LFS, you would do something like:

git lfs track "*.mp4"

... which would ensure LFS was used for all of your mp4 files.

If you want to be able to "lock" the files, be sure to add the --lockable parameter.

When you do this, a new entry is added to your .gitattributes file and one is created if it doesn't exist yet. It will look something like:

*.mp4 filter=lfs diff=lfs merge=lfs -text lockable
*.mp3 filter=lfs diff=lfs merge=lfs -text lockable
...

Be sure to add the .gitattributes file so that git tracks it.

git add .gitattributes
git commit

You may wish to use the following command to list all the unique extensions of files that are larger than 1 Megabyte.

find . -type f -size +1M | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

Locking

Because we are messing with binary files which cannot be diff-merged, we probably want to utilize locking.

Lock A File

git lfs lock images/banner.png

View Locks

git lfs locks

Unlock A File

When you have finished editing a file that you locked, be sure to unlock it so others know they can edit it.

git lfs unlock images/banner.png

If you weren't the one to lock the file and you have to unlock it, then use the --force parameter, but this will only work if you have maintainer privileges on the repo.

References

Last updated: 25th June 2019
First published: 25th June 2019