# Trigger deploys on Netlify with submodules

> Learn how to trigger a Netlify rebuild when a Git submodule changes by calling a Netlify build hook from a GitHub Action that runs on every push.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2022-07-20 | Topics: [Git](https://flaviocopes.com/tags/git/) | Canonical: https://flaviocopes.com/netlify-deploy-git-submodule-github-actions/

I wanted to rebuild my site on [Netlify](https://flaviocopes.com/netlify/) any time I did a new commit on a [Git](https://flaviocopes.com/git/) submodule included in the repo.

Unfortunately Netlify does not do this by default, only the main repository is "watched" for new commits.

So I did this. 

I went in the Deploy settings and in "Build hooks" I clicked "Add build hook".

![Netlify build hooks configuration dialog with hook name Trigger deploy from submodule and branch set to main](https://flaviocopes.com/images/netlify-deploy-git-submodule-github-actions/Screen_Shot_2022-07-05_at_14.32.06.png)

Saving this gave me a unique URL I could call, something like `https://api.netlify.com/build_hooks/UNIQUE_STRING`.

Then I created a [GitHub](https://flaviocopes.com/github/) Action in the submodule repository:

```
name: Trigger redeploy on Netlify
on:
  push:
    branches: [ "main" ]
jobs:
  build:
    name: Make POST request
    runs-on: ubuntu-latest
    steps:
      - name: Curl request
        shell: bash
        env:
          UNIQUE_STRING: ${{ secrets.NETLIFY_BUILD_HOOK_UNIQUE_STRING }}
        run: curl -X POST -d {} https://api.netlify.com/build_hooks/$UNIQUE_STRING
```

Add the value of the Netlify UNIQUE_STRING value you to above in `NETLIFY_BUILD_HOOK_UNIQUE_STRING` Action secret in your repo Settings -> Secrets -> Actions.

If you need a starting point for other deploy workflows, I built a free [GitHub Actions deploy workflow generator](https://flaviocopes.com/tools/gh-actions-deploy/) that writes the YAML for the most common targets.

Commit the action and the deploy should already be working:

![Netlify deployment status showing Building state triggered by hook Trigger deploy from submodule](https://flaviocopes.com/images/netlify-deploy-git-submodule-github-actions/Screen_Shot_2022-07-05_at_14.43.30.png)
