Skip to content

Instantly share code, notes, and snippets.

@nikolaykasyanov
Last active March 28, 2023 12:36
Show Gist options
  • Save nikolaykasyanov/5913ca2d75ff28819bfc to your computer and use it in GitHub Desktop.
Save nikolaykasyanov/5913ca2d75ff28819bfc to your computer and use it in GitHub Desktop.
Useful pre-commit hook for submodules

Put pre-commit file into your submodule's hooks directory and make it executable.

In recent git versions submodule hooks directory will be located in $(parent-repo-path)/.git/modules/<relative path of your submodule>/hooks/.

#!/bin/sh
if git status | grep -i 'HEAD detached' > /dev/null 2>&1; then
echo "You should not commit while in detached state, either create a new brach or checkout existing one before committing."
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment