Getting Started with LFS in GitLab
Related Posts
Steps
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.programster.org.com:23825/my-group/my-project-name
cd my-project-name
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.
--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
Nginx Proxy - Increase Limits
If you experience issues uploading LFS objects to Gitlab and you are using an Nginx reverse proxy, be sure to increase the client_max_body_size
variable.
This is because all LFS objects are sent over https instead of SSH.
For me, this variable was in a file called /etc/nginx/proxy.conf
but yours might me elsewhere.
You may also wish to increase your timeouts. E.g.
- proxy_connect_timeout
- proxy_send_timeout
- proxy_read_timeout
- keepalive_timeout
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
--force
parameter, but this will only work if you have maintainer privileges on the repo.
References
First published: 25th June 2019