Run `git submodule update --remote` before build (or otherwise keep submodule up-to-date)

Hi!

I’ve been playing around with using a private submodule for content. It’s mostly working the way I want it to. I followed Repository permissions and linking | Netlify Docs.

I also followed Trigger deploys on Netlify with submodules (to trigger a deploy when the submodule repo is updated) and have that working as well.

The only thing that’s not happening: Submodule changes are not automatically reflected.

I thought this would do what I wanted: How can I specify a branch/tag when adding a Git submodule? - Stack Overflow – but on closer examination, it still requires running git submodule update --remote, it just makes the process more straightforward.

I’m aware that I can do this with GitHub Actions, as described in git - Using GitHub Actions to automatically update the repo's submodules - Stack Overflow, but I’d like to avoid adding a commit to the superproject every time the submodule is updated, to keep the history cleaner.

I figured this would be as simple as adding something like this to "scripts" in package.json:
"update_and_build": "git submodule update --remote && npm run build"
(and having Netlify use that as the build command)
… but alas, it fails, as it needs the deploy key (on account of the submodule being a private repo), which I gather is not available.

Is there a known solution to this scenario?

I’ve looked around this forum, and read Git submodule pull problem - #17 by r0x0r & Netlify SSH Deploy key private key location.

Thanks!

Hi, @mrienstra. To keep the submodule up to date in the parent repo, you must make commits to the parent repo to point to the most recent commit in the submodule repo.

There is a Stack Overflow post with more information here:

Your parent repo points to a specific commit in the submodule. That means that this won’t be avoidable:

I’d like to avoid adding a commit to the superproject every time the submodule is updated, to keep the history cleaner.

You must make a new commit in the parent repo to update the submodule. That is just how Git is designed.

1 Like