| Start |
|---|
| Pre-push Available in Git 1.8.2 (opens new window) and above. 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 simply creating a file named Here's an example from Hannah Wolfe (opens new window) that blocks a push to master: Here's an example from Volkan Unsal (opens new window) which makes sure RSpec tests pass before allowing the push: As you can see, there are lots of possibilities, but the core piece is to When using client side hooks, keep in mind that users can skip all client side hooks by using the option "--no-verify" on a push. If you're relying on the hook to enforce process, you can get burned. Documentation: https://git-scm.com/docs/githooks#_pre_push (opens new window) |
| Verify Maven build (or other build system) before committing
|
| Automatically forward certain pushes to other repositories
In this example, the |
| Commit-msg This hook is similar to the The only argument passed to this hook is the name of the file that contains the message. If you don't like the message that the user has entered, you can either alter this file in-place (same as The following example is used to check if the word ticket followed by a number is present on the commit message |
| Local hooks 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 down the road. There are six types of local hooks: pre-commit, prepare-commit-msg, commit-msg, post-commit, post-checkout, and pre-rebase. The first four hooks relate to commits and allow you to have some control over each part in a commit's life cycle. The final two let you perform some extra actions or safety checks for the git checkout and git rebase commands. All of the "pre-" hooks let you alter the action that’s about to take place, while the "post-" hooks are used primarily for notifications. |
| Post-checkout This hook works similarly to the This hook accepts three parameters:
Its exit status has no affect on the |
| Post-commit This hook is called immediately after the The script takes no parameters, and its exit status does not affect the commit in any way. |
| Post-receive 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-commit This hook is executed every time you run This type of hook is useful for running automated tests to make sure the incoming commit doesn't break existing functionality of your project. This type of hook may also check for whitespace or EOL errors. No arguments are passed to the pre-commit script, and exiting with a non-zero status aborts the entire commit. |
| Prepare-commit-msg This hook is called after the One to three arguments are passed to this hook:
Similar to |
| Pre-rebase This hook is called before This hook takes 2 parameters:
You can abort the rebase operation by exiting with a non-zero status. |
| Pre-receive This hook is executed every time somebody uses The hook runs before any references are updated. It is typically used to enforce any kind of development policy. The script takes no parameters, but each ref that is being pushed is passed to the script on a separate line on standard input in the following format: |
| Update This hook is called after This hook accepts the following 3 arguments:
This is the same information passed to Syntax
Remarks
Information on this page was gathered from the official Git docs (opens new window) and Atlassian (opens new window). |
Read Article
https://develop.horje.com/learn/1434/reference