Skip to content

Instantly share code, notes, and snippets.

@tkengo
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tkengo/9320008 to your computer and use it in GitHub Desktop.
Save tkengo/9320008 to your computer and use it in GitHub Desktop.
#/bin/sh
template_dir=$HOME/.git_template
hook_dir=$template_dir/hooks
pre_push=$hook_dir/pre-push
hook_script='[ "$(git rev-parse --abbrev-ref HEAD)" = "master" ] && echo "You cant push the master branch to the remote" && exit 1'
current_template_dir="$(git config -l | grep init.templatedir)"
current_template_dir=${current_template_dir#init.templatedir=}
if [ -n "$current_template_dir" -a "$current_template_dir" != "$template_dir" ]; then
mkdir -p $current_template_dir/hooks
pre_push=$current_template_dir/hooks/pre-push
else
mkdir -p $hook_dir
git config --global init.templatedir $template_dir
fi
if [ -e $pre_push ]; then
[ -n "$(grep 'You cant push the master branch to the remote' $pre_push)" ] && exit 1
fi
echo $hook_script >> $pre_push
echo exit 0 >> $pre_push
chmod +x $pre_push
echo OK, all set.
echo 'All you need to do is that executing "git init" in your existing git project directory.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment