Create a template of post-receive
hooks to be populated in the .git
folder everytine we initialize a repo.
The template directory should be registered in to the glogal git configuration. Create the hook subdirectory inside the folder.
$ git config --global init.templatedir '~/.git-templates'
$ mkdir -p ~/.git-templates/hooks
Create the file post-receive.sample
inside the hook directory, and set the file to be executable chmod +x ~/.git-templates/hooks/post-receive.sample
below is the content of the file.
#!/bin/sh
#
# An example hook script to update the working tree, including its
# submodules, after receiving a push.
#
# This hook requires core.worktree to be explicitly set, and
# receive.denyCurrentBranch to be set to false.
#
# To enable this hook, rename this file to "post-receive".
# Read standard input or hook will fail
while read oldrev newrev refname
do
:
done
# Unset GIT_DIR or the universe will implode
unset GIT_DIR
# Change directory to the working tree; exit on failure
cd `git config --get core.worktree` || exit
# Force checkout
git checkout --force
# Force update submodules
git submodule update --init --recursive --force
$ cd /path/to/your/working/folder
$ git init
$ git config --bool receive.denyCurrentBranch false
$ git config --path core.worktree ../
$ mv .git/hooks/post-receive.sample .git/hooks/post-receive