Git hooks are custom scripts that are automatically run in Git when certain events occur, such as
before commit, after commit, before push, and more. By using
Git hooks, you can automate tasks and apply custom rules in your workflow.
There are two types of
Run on your local machine when interacting with a
pre-commit: Runs before committing. You can use it to perform code checks, coding standards validation, or formatting.
pre-push: Runs before pushing. You can use it to run unit tests or ensure that the code meets project standards and rules.
Run on the remote server when receiving tasks from the local machine.
pre-receive: Runs before receiving commits from the local machine. You can use it to check if the commits meet the required criteria before accepting them.
post-receive: Runs after receiving commits from the local machine. You can use it for notifications, deployment, or other actions after receiving the commits.
Git hooks, you need to create custom shell scripts and place them in the
.git/hooks directory in your
Git repository. Make sure you have granted execution permissions to the scripts.
Git hooks, you can automate tasks such as source code checks, coding standards validation, formatting, notifications, and automatic deployments. This helps ensure that your workflow adheres to rules and achieves consistency in source code management.