Git LFS on Heroku

Git LFS allows you to version large files while storing them outside of your Git repository. Heroku doesn’t have built-in support for it, so a few additional steps are needed to make it work. Keep in mind that Heroku’s maximum slug size is 500 MB compressed.

This tutorial assumes you’re already using Git LFS and are ready to deploy your app to Heroku.

Getting Started

We’ll use two buildpacks: one for SSH keys and another for Git LFS.

heroku buildpacks:add --index 1
heroku buildpacks:add --index 2

Next, specify the location of the repo. Use the SSH url (not HTTPS).

heroku config:set


GitHub, GitLab, and Bitbucket all support read-only access with SSH keys. Generate an SSH key pair:

ssh-keygen -f /tmp/heroku_rsa -N ""

Add the public key to your Git provider.

Provider From the repository page, go to...
GitHub Settings > Deploy Keys
GitLab Settings > Repository > Deploy Keys
Bitbucket Repository settings > Access keys

And copy and paste the output of:

cat /tmp/

Add the private key to your Heroku app.

heroku config:set BUILDPACK_SSH_KEY="$(cat /tmp/heroku_rsa)"


Finally, use the --no-verify flag to deploy.

git push heroku master --no-verify

Otherwise, it’ll fail with:

batch response: Repository or object not found:
Check that it exists and that you have proper access to it

Set up an alias to save some typing.

alias gpp="git push heroku master --no-verify"

We’ve now successfully deployed a repo with Git LFS to Heroku.

Published October 31, 2020

You might also enjoy

DVC on Heroku

Scaling the Monolith

Score Almost Any Machine Learning Model in Ruby

All code examples are public domain.
Use them however you’d like (licensed under CC0).