Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change default git hooks

Tags:

git

githooks

Not sure if this is possible in git (I haven't found it but I may be using the wrong vocabulary in my searches), but it be would useful to be able to modify and enable hooks as the defaults for all new repositories (at the time of creation I mean) so these don't have to be customized each time a new repository is created. It seems the easy way to do this is write a wrapper that sets my hooks and chmods them when I create a new repository, but if there's a way built into git I would rather use that instead of having unnecessary wrapper scripts however little lying around.


Clarification copied up from a comment to a now-deleted answer:

My question is whether the default behavior for ALL new repositories can be changed, so they don't need to be customized in the same way each time for each new repository. The easy answer is write a wrapper for creating and customizing the repos (it generates the hook scripts and chmods them), but it seems like this default behavior should also be customizable without having to do that.

like image 494
rplevy Avatar asked Dec 29 '09 23:12

rplevy


People also ask

How do I change the git hook directory?

By default the hooks directory is $GIT_DIR/hooks , but that can be changed via the core. hooksPath configuration variable (see git-config[1]). Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository.

How do I disable pre-commit hooks?

Quick tip if you want to skip the pre-commit validations and quickly want to get a commit out there. To get your commit through without running that pre-commit hook, use the --no-verify option. Voila, without pre-commit hooks running!

Where are git hooks stored?

The hooks are all stored in the hooks subdirectory of the Git directory. In most projects, that's . git/hooks .

Can I push git hooks to remote?

No. Hooks are per-repository and are never pushed.


1 Answers

From the git-init man page (also works with git-clone if you are cloning an existing repo instead of creating a new one from scratch):

        --template=<template_directory>            Provide the directory from which templates will be used. The            default template directory is /usr/share/git-core/templates.             When specified, <template_directory> is used as the source of the            template files rather than the default. The template files include            some directory structure, some suggested "exclude patterns", and            copies of non-executing "hook" files. The suggested patterns and            hook files are all modifiable and extensible. 

You can modify the system-wide template directory (which defaults to /usr/share/git-core/templates, but may be in a different location on your machine), you can supply --template=<template_directory> on the command line when you create or clone the repo, or you can configure the default template directory in your config file:

[init]      templatedir = /path/to/templates 
like image 161
Brian Campbell Avatar answered Sep 24 '22 02:09

Brian Campbell