B. Server-Side Hooks

1. pre-receive: This hook reacts to git push and updates the references in its repository. It takes no arguments but for each ref to be updated it receives standard input in this format.

<old-value> SP <new-value> SP <ref-name> LF>

where <old-value> is the old object name stored in the ref, <new-value> is the new object name to be stored in the ref, and <ref-name> is the full name of the ref. If the hook exits with a non-zero status, none of the refs will be updated.

2. update: Before updating the ref on the remote repository, the update hook is invoked. Its exit status determines the success or failure of the ref update. It takes three arguments as follows: 

  • the name of the ref being updated
  • the old object name is stored in the ref
  • and the new object name to be stored in the ref.

3. post-receive: It executes on the remote repository once all the refs have been updated. It takes no arguments but gets the same information as the pre-receive hook does on its standard input.



Git – Hooks

Git hooks are scripts that Git executes before or after specific events, such as committing, merging, and pushing. These hooks allow you to automate tasks, enforce policies, and customize your Git workflow. In this article, we’ll explore Git hooks in detail, covering their types, usage, and practical examples.

Similar Reads

What are Git Hooks?

Git hooks are stored in the .git/hooks directory of your Git repository. Each hook is a script file named after the event it triggers. Git provides both client-side and server-side hooks. Client-side hooks run on your local machine, while server-side hooks execute on the Git server....

Types of Git Hooks

Client-Side hooksServer-Side hooks...

B. Server-Side Hooks

1. pre-receive: This hook reacts to git push and updates the references in its repository. It takes no arguments but for each ref to be updated it receives standard input in this format....

Contact Us