Uploading large media files without building the site (?)


I’m using git-lfs and i’m wondering if there is a way to prevent the trigger of a build when the last commits only contains lfs files since there is no use to rebuild the site and I just need the files to be uploaded to the Large Media service.

All my lfs files are located in a specific “images” directory that i’m tracking, so I’ve tried the following conf in my netlify.toml:

  ignore = "git diff --quiet HEAD^ HEAD -- . ':!images'"

but the build of the site is still triggered. I’ve checked the exit code of the git command and it seems fine.

Am i missing something? Is this syntax not working? or there is just no way to upload the files without a build?

Thanks for your help

Hi, @stephanie-w, would you please add that to your build command without the --quiet and test uploading only an image again?

So, if your build command is currently:

npm run build

Make the build command this for one image upload only:

git diff HEAD^ HEAD -- . ':!images' ; npm run build 

This will show the diff command output in the deploy logs and we can see what other file is changing. I tested this in a test repo using Large Media, and I see my .gitattributes file changing when I exclude the image directory:

$ git diff HEAD^ HEAD -- . ':!pre'
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..66155f7
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,4 @@
+pre/logo.svg filter=lfs diff=lfs merge=lfs -text
+pre/test.svg filter=lfs diff=lfs merge=lfs -text
+pre/green-river.png filter=lfs diff=lfs merge=lfs -text
+pre/large.jpg filter=lfs diff=lfs merge=lfs -text

Also, if you do see it is .gitattributes being counted in the git diff, there is a way to exclude it:

  ignore = "git diff --quiet HEAD^ HEAD -- . ':!images' ':!.gitattributes'"

The solution above it might “just work” and so please feel free to just skip to testing this solution first if you prefer.

If there are other questions, we’re happy to answer.

Hello Luke,

I’ve tried both.
I’ve added the .gitattributes in the command line :

  ignore = "git diff --quiet HEAD^ HEAD -- . ':!images' ':!.gitattributes'"

I’ve changed the build command to see the output of the git diff :

10:25:03 AM: Detected ignore command in Netlify configuration file. Proceeding with the specified command: 'git diff --quiet HEAD^ HEAD -- . ':!images' ':!.gitattributes''

10:25:14 AM: Executing user command: git diff HEAD^ HEAD -- . ':!images'; echo $?;jekyll build --future
10:25:14 AM: 0
10:25:14 AM: Configuration file: /opt/build/repo/_config.yml
10:25:14 AM:             Source: /opt/build/repo
10:25:14 AM:        Destination: /opt/build/repo/_site
10:25:14 AM:  Incremental build: disabled. Enable with --incremental
10:25:14 AM:       Generating...
10:25:14 AM: Building site for default language: "en" to: /opt/build/repo/_site
10:25:15 AM:        Jekyll Feed: Generating feed for posts

It didn’t solve the issue. The site is still built and i don’t understand why.

Thanks for your help.


This part of the build command:

git diff HEAD^ HEAD -- . ':!images'; echo $?

is responsible for the second line below:

10:25:14 AM: Executing user command: git diff HEAD^ HEAD -- . ':!images'; echo $?;jekyll build --future
10:25:14 AM: 0

The “0” is the exit code of zero for the git diff. However, git diff only returns non-zero exit codes if the --quiet option is used (or there is actually an error). That option was not usedso the zero exit is expected.

However, there is no diff printed either, which is quite unexpected. That is something I would like to research as it should have shown what the difference was. Would you please send us a link to the deploy where this occurred?

Hello luke,

Putting the git diff in a exit-zero.sh script seems to fix the issue

    ignore = "./exit-zero.sh"

exit-zero.sh content is:


git diff --quiet --exit-code HEAD^..HEAD -- . ':!images' ':!.gitattributes'

The build is indeed canceled (see deploy 5e83add6797c060006290a4b vs 5e83ab1ad424f400060eb7ab)

But with the cancel of the build, the file pushed on the git repo in the last commit is not uploaded to the Large Media service so i guess there is no way to “bypass” the build to just upload files to the service (?).


Hi @stephanie-w, the fil is uploaded to your lfs store when you do the push on your local machine, it’s not pushed to lfs during the netlify build process so whether the build is canceled or not should not actually matter in terms of having the same in your LFS store or not.

Hi Luke,

Right, but what i need is the file to be available on the site, ie. pushed on the CDN without building the site when there is nothing to rebuild (since there is no change in the site code).
Sorry to have been unclear or ambiguous :slight_smile:

So i’ve just focused on drastically decrease the build time so the files are on the site faster after they have been pushed on your lfs store.

Thanks for your help anyway.


1 Like