1

I have three git repositories: A, B, and C. C is a superproject including submodules A and B, tracking each submodule's respective master branch.

When the master branch of A or B is changed, I must do the following in C:

git submodule update --remote
git add A
git add B
git commit -m "Update submodule A or B"
git push

At this point an automated build and deploy from C is executed.

I'm looking for ways to streamline this process. Ideally, any commit to the master branch of A or B would trigger a hook to update, commit, and push to C. Any ideas how to achieve this?

Edit: In case there's a vendor-specific feature I should be aware of, I'm using Azure DevOps for the git hosting and Azure Pipelines for the build and deploy process.

user276833
  • 77
  • 6

1 Answers1

0

You can use a git post-commit hook, when you do a commit in the submodules the hook will be executed and will do the commands.

  1. Go to each sub module repo.
  2. Create file .git/hooks/post-commit with following content:

    #!/bin/sh
    
    branch="$(git rev-parse --abbrev-ref HEAD)"
    
    if [ "$branch" = "master" ]; then
      cd {super repo location}
      git submodule update --remote
      git add A
      git add B
      git commit -m "Update submodule A or B"
      git push
    fi
    
  3. Make it executable (not required on Windows):

    $ chmod +x .git/hooks/pre-commit
    
Shayki Abramczyk
  • 36,824
  • 16
  • 89
  • 114