Problem checking out file stored in git LFS on Github

Hi, I’m having trouble deploying from a repository that uses Github’s LFS. The file is stored in Github here:

Note the “Stored with Git LFS” header. My latest branch deploy is here:

https://65238e3ed713cf3d1262c490--zakj.netlify.app/fonts/GT-Walsheim-Black.woff2

Instead of the contents of the file, I’m seeing git-lfs metadata:

version https://git-lfs.github.com/spec/v1
oid sha256:cc9311d1aea34923c6590a55bfcdb66a5cdec627fa11022e9383aec06aab79a5
size 46256

I have tried with GIT_LFS_ENABLED both enabled and disabled in the environment, with no change in behavior. I have tried clearing the build cache. There are no errors or surprises in the build log. A local clean clone and build works correctly. I feel like I must be missing something obvious. :confused: Thanks for any help!

Curiously, other (image) files stored in LFS are checked out correctly!

On the advice of another thread, I added git lfs pull to my build script, and got this in the build log:

9:49:20 PM: $ git lfs pull && npm run build
9:49:20 PM: Skipping object checkout, Git LFS is not installed.

Updating my build command to include both git lfs install && git lfs pull “fixed” the problem, but that seems really strange—and definitely wasn’t listed in any of the Netlify docs I could find. Any idea why it was necessary in this case?

As I already mentioned here, zip files were not downloading properly for us, even though image files worked fine from GitHub LFS. Probably you need to set GIT_LFS_FETCH_INCLUDE to something like *.woff2,*.jpg,*.png,*.jpeg,*.svg,*.gif,*.pdf,*.mp4,*.bmp,*.webp together with GIT_LFS_ENABLED true.

1 Like

Today is 2023-12-06. I signed up for an account here just to make sure that the correct, WORKING solution was ACTUALLY highlighted for people experiencing problems with Git LFS on GitHub hosted repositories like I was.

That was it. That’s what fixed it.

zakj’s solution is what made the Git LFS files start to be included in the deployed application.

rvilums’s solution did absolutely nothing. In fact, none of the other environment variables having to do with Git LFS did anything either. So the fact that they’re left in the Netlify toml documentation is actually harmful and misleading. Deprecated arguments like these should be removed from the docs as soon as they’re removed from the product.

Here is my complete, working solution, split up into 2 separate files, so I was able to get the maximum amount of build logging for when things did and didn’t work.

netlify.toml

[build]
command = "./netlify_build.sh"

[build.environment]
NETLIFY_BUILD_DEBUG = "true"

netlify_build.sh

set -e
echo "Attempting to 'git lfs install'"
# This right here was the kicker. The thing that made it work on the build box.
git lfs install
echo "Attempting to 'git lfs pull'"
git lfs pull
echo "Attempting to 'yarn run build'"
yarn run build

Good luck out there to anyone who’s project is broken due to LFS issues!

Hi, @AdmiralPotato. First, stop writing sentences with words in all upper-case letters when posting on this forum. It is considered rude and continued rudeness will result in a ban. This will be the only warning about such behavior. If you are polite going forward, nothing more will be said about this.

Second, @rvilums’s solution is absolutely the correct solution for .woff2 and .zip files not being LFS cloned. This means that you are not highlighting the actual solution and, unfortunately, you are instead mudding the waters by providing an incorrect analysis.

Finally, I want to explain what both you and @zakj experienced in more detail and why git lfs install is fixing the issue for you.

It is normally not required in anyway at Netlify for git lfs install to be run in the build system to clone LFS objects. All that is required is to use the environment variable GIT_LFS_ENABLED=true and Netlify will clone using Git LFS. Again, you do need to use GIT_LFS_FETCH_INCLUDE to clone file extensions which are not included as the defaults. (This is why @rvilums’s solution is correct for r .woff2, .zip, and any other file extensions not included as defaults.)

An edge case occurs when an existing repo is modified to add Git LFS after Netlify has already cloned the repo. The cloned repo is stored in a cache. The cached repo in the build system doesn’t have Git LFS enabled because it wasn’t enable on the repo when it was first cloned. This results in the behavior of Git LFS clones not working even when the environment variable GIT_LFS_ENABLED=true is set.

There are two possible solutions at this point:

  • solution 1: rungit lfs install to install Git LFS to the locally cloned repo
  • solution 2: trigger a new deploy with the “clear cache” option

The second workflow above requires no code changes and, instead, only takes a few clicks in the Netlify UI.

Now, if you disagree with anything I’ve said here, we are willing to examine this in more detail. For example, do you have a link to where you tested these deploys at Netlify? (You can share a deploy id or a site id to identify the site where this testing was done.)