Table of Contents
- Git Hooks
- Git-managed(shared) hook scripts: copy or symlink them to
- In a git hook, is the working directory guaranteed to be within the git repository?
Git Hooks tutorial
applypatch-msg.sample commit-msg.sample fsmonitor-watchman.sample post-update.sample pre-applypatch.sample pre-commit.sample pre-push.sample pre-rebase.sample pre-receive.sample prepare-commit-msg.sample update.sample
You can modify these files and remove
.sample extension to activate hooks.
There are two kinds of hooks:
- Local Hooks
- Server-side Hooks
Git-managed(shared) hook scripts: copy or symlink them to
Managing hooks under the repository is good to share the same scripts between developers. As we can't manage files under
.git we should decided to copy or symlink scripts into
Make sure the scripts are executable.
Copy if your scripts are independent. In this way, the hooks will work consistently regardless of the current branch.
cp scripts/pre-push .git/hooks/
Symlink if your scripts are constantly changing. In this way, developers don't need to copy them to
.git/hooksevery time the scripts change.
ln -s ../../scripts/foo.sh .git/hooks/pre-commit
In a git hook, is the working directory guaranteed to be within the git repository? discussion
Before Git invokes a hook, it changes its working directory to either the root of the working tree in a non-bare repository, or to the
$GIT_DIRin a bare repository.