Tutorial by Examples

This hook is similar to the prepare-commit-msg hook, but it's called after the user enters a commit message rather than before. This is usually used to warn developers if their commit message is in an incorrect format. The only argument passed to this hook is the name of the file that contains the ...
Local hooks affect only the local repositories in which they reside. Each developer can alter their own local hooks, so they can't be used reliably as a way to enforce a commit policy. They are designed to make it easier for developers to adhere to certain guidelines and avoid potential problems dow...
This hook works similarly to the post-commit hook, but it's called whenever you successfully check out a reference with git checkout. This could be a useful tool for clearing out your working directory of auto-generated files that would otherwise cause confusion. This hook accepts three parameters:...
This hook is called immediately after the commit-msg hook. It cannot alter the outcome of the git commit operation, therefore it's used primarily for notification purposes. The script takes no parameters, and its exit status does not affect the commit in any way.
This hook is called after a successful push operation. It is typically used for notification purposes. The script takes no parameters, but is sent the same information as pre-receive via standard input: <old-value> <new-value> <ref-name>
This hook is executed every time you run git commit, to verify what is about to be committed. You can use this hook to inspect the snapshot that is about to be committed. This type of hook is useful for running automated tests to make sure the incoming commit doesn't break existing functionality of...
This hook is called after the pre-commit hook to populate the text editor with a commit message. This is typically used to alter the automatically generated commit messages for squashed or merged commits. One to three arguments are passed to this hook: The name of a temporary file that contains ...
This hook is called before git rebase begins to alter code structure. This hook is typically used for making sure a rebase operation is appropriate. This hook takes 2 parameters: the upstream branch that the series was forked from, and the branch being rebased (empty when rebasing the current b...
This hook is executed every time somebody uses git push to push commits to the repository. It always resides in the remote repository that is the destination of the push and not in the originating (local) repository. The hook runs before any references are updated. It is typically used to enforce a...
This hook is called after pre-receive, and it works the same way. It's called before anything is actually updated, but is called separately for each ref that was pushed rather than all of the refs at once. This hook accepts the following 3 arguments: name of the ref being updated, old object na...
Available in Git 1.8.2 and above. 1.8 Pre-push hooks can be used to prevent a push from going though. Reasons this is helpful include: blocking accidental manual pushes to specific branches, or blocking pushes if an established check fails (unit tests, syntax). A pre-push hook is created by simpl...
.git/hooks/pre-commit #!/bin/sh if [ -s pom.xml ]; then echo "Running mvn verify" mvn clean verify if [ $? -ne 0 ]; then echo "Maven build failed" exit 1 fi fi
post-receive hooks can be used to automatically forward incoming pushes to another repository. $ cat .git/hooks/post-receive #!/bin/bash IFS=' ' while read local_ref local_sha remote_ref remote_sha do echo "$remote_ref" | egrep '^refs\/heads\/[A-Z]+-[0-9]+$' >/dev/null &am...

Page 1 of 1