Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git hook to call `git submodule update` automatically.
#!/bin/sh
echo "[post-rewrite hook: $1]"
# quick script to call "git submodule update" automatically if the
# .gitmodules file is changed
changedfiles=( `git diff-tree --no-commit-id --name-only HEAD@{1} HEAD` )
if [[ "${changedfiles[*]}" =~ ".gitmodules" ]]; then
echo "initializing & updating submodule(s)"
git submodule update --init --recursive
fi
@digitaljhelms

This comment has been minimized.

Copy link
Owner Author

@digitaljhelms digitaljhelms commented Sep 22, 2014

Triggered if the .gitmodules file is modified by changes being incorporated from a remote repository into the current branch (via git pull and thus git merge, or git rebase). This file should be named "post-rewrite", marked executable, and placed in .git/hooks/ within a local Git clone.

Note: could be modified [with a few edits] to be combined with https://gist.github.com/digitaljhelms/7901283

@fitzage

This comment has been minimized.

Copy link

@fitzage fitzage commented Oct 5, 2017

I'm not sure why, but (three years later) I tried to implement this as a post-rewrite hook and it didn't work. It does work fine as post-merge, though. Git version issue maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment