Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between pre-push and pre-receive hook in git?

Tags:

git

githooks

Is there a difference between pre-push and pre-receive hook in git, in terms of use case or working logic?
The only difference I could understand from their documentation was in terms of the input they receive -

1.Pre-Push : Information about what is to be pushed is provided on the hook's standard input with lines of the form - local ref SP local sha1 SP remote ref SP remote sha1 LF

2.Pre-receive : For each ref to be updated it receives on standard input a line of the format -
old-value SP new-value SP ref-name LF
However, I would like to know if there are particular use cases for each hook or can they be used interchangeably?

like image 970
phoenix Avatar asked Aug 22 '14 05:08

phoenix


1 Answers

One (pre-push) is a client-side hook, the other (pre-receive) is a server-side hook.

In that aspect, they are very different, and if you want to enforce consistently a given policy, you often do it in a pre-receive (server side) hook. That way, you don't have to worry about deploying a pre-push hook on each client.

Remember: hooks are local to a repo, which means a pre-push hook cannot easily be distributed to any downstream repo. But if those downstream repos are all referring to the same upstream repo, a pre-receive hook can apply to them all.

like image 170
VonC Avatar answered Sep 18 '22 08:09

VonC