If a project's best practices need to be strictly enforced, server-side hooks are the way to do it. Developers can choose to disable all client-side hooks if they wish. Server-side hooks are triggered by the git-receive-pack command, which is a result of developers pushing changes to the remote repository on a cloud-hosted Git server.ĭevelopers have full control of client-side hooks. Any of these commands can trigger their relevant client-side hooks. Committing, merging, rebasing, applying patches, and checkout are common Git operations that developers do on their development machines. Source: Adapted from Git SCM 2022a.Ĭlient-side hooks run on developer machines whereas server-side hooks run on the server that hosts the repository. What are client-side and server-side hooks?Ī summary of hooks in Git v2.36.0.The update hook that runs once per branch can be used to enforce access control, that is, only authorized users can push to a branch. This hook can also deploy the latest changes to production. More commonly, when collaboration is via a remote repository, notifications are sent from the post-receive hook that's triggered after all references are updated. Hooks prepare-commit-msg and commit-msg can be used to format/validate the commit message.Īfter a successful commit, the hook post-commit could be used to send notifications. By checking for missing semicolons, trailing whitespace, and debug statements code reviews can focus on more important issues. This hook can format the code against the project's styling guide, run linting or execute unit tests. The pre-commit hook is called when the commit procedure begins. Hooks are invoked by naming convention before or after specific events. The figure illustrates local add/commit followed by a push to the remote repository. Some Git commands and their associated hooks.
0 Comments
Leave a Reply. |