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 |