It sometimes happens that you move to a new machine and forget to setup your name and email address. To find this out after 10 commits can be quite frustrating.
As far as I know all "sane" workflows involve topic branches, so normally a developer will never commit directly on master but use topic branch instead and merge them into master once finished.
One thing which could be dangerous is if you clone a project containing submodules. If you would immediately start working in a submodule you would create commits with detached head. This can be a dangerous operation in terms of loosing commits and should be forbidden by default.
Signed-off-by: Heiko Voigt <git-list@hvoigt.net> ---
I also would like to vote for enabling some hooks by default.
templates/hooks--pre-commit.sample | 23 +++++++++++++++++++++++ 1 files changed, 23 insertions(+), 0 deletions(-)
Show changes to templates/hooks--pre-commit.sample +23 −0
diff --git a/templates/hooks--pre-commit.sample b/templates/hooks--pre-commit.sample index 0e49279..6360da0 100755 --- a/templates/hooks--pre-commit.sample +++ b/templates/hooks--pre-commit.sample @@ -16,3 +16,26 @@ else fi exec git diff-index --check --cached $against -- + +# check if username and email are setup +if [ -z "$(git config --global user.name)" ]; then + echo "Please set your name and email address" + exit 1 +fi +if [ -z "$(git config --global user.email)" ]; then + echo "Please set your name and email address" + exit 1 +fi + +# work should always be done on a feature branch +if git branch | grep "^* master" > /dev/null; then + echo "No commits on master, please !" + exit 1 +fi + +# do not allow commits on detached head +if git branch | grep "^* (no branch)" > /dev/null; then + echo "Commit on detached HEAD is dangerous !" + echo "Please checkout a branch first ..." + exit 1 +fi
-- 1.6.1.2.390.gba743