# Post-receive hook for "git pull"

3 messages from 2015-12-07 to 2016-02-12. Participants: Stefan Monnier, Junio C Hamano.
Thread: https://gitlist.dev/t/40952

## Stefan Monnier, 2015-12-07 13:47

Subject: Post-receive hook for "git pull"
Message-ID: <jwv4mful6nu.fsf-monnier+gmane.comp.version-control.git@gnu.org>
URL: https://gitlist.dev/e/jwv4mful6nu.fsf-monnier%2Bgmane.comp.version-control.git%40gnu.org

```
I have a system here where it can be quite common to have thousands of
branches in the remote repository, and where I'd like to update some
local state according to the appearance of new branches (or updates of
pre-existing ones).

Currently, I use a "git for-each-ref" after pulling and then check (for
each one of those refs) if an update is warranted, but this can get slow
with that many branches.  Is there some way to get something like the
post-receive hook to be run for "git pull", so that the script gets told
directly which (remote tracking) branches have been modified/created?


        Stefan

```

## Junio C Hamano, 2015-12-07 19:54

Subject: Re: Post-receive hook for "git pull"
Message-ID: <xmqqio4am3uk.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqio4am3uk.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <jwv4mful6nu.fsf-monnier+gmane.comp.version-control.git@gnu.org>

```
Stefan Monnier <monnier@iro.umontreal.ca> writes:

> I have a system here where it can be quite common to have thousands of
> branches in the remote repository, and where I'd like to update some
> local state according to the appearance of new branches (or updates of
> pre-existing ones).
>
> Currently, I use a "git for-each-ref" after pulling and then check (for
> each one of those refs) if an update is warranted, but this can get slow
> with that many branches.  Is there some way to get something like the
> post-receive hook to be run for "git pull", so that the script gets told
> directly which (remote tracking) branches have been modified/created?

I do not think there is.  But you could easily script along the
lines of...

    #!/bin/sh
    git for-each-ref | sort >prestate
    git pull "$@"
    git for-each-ref | sort >poststate
    comm -12 prestate poststate

... or something like that, no?

```

## Stefan Monnier, 2016-02-12 13:39

Subject: Re: Post-receive hook for "git pull"
Message-ID: <jwvlh6qt5i6.fsf-monnier+gmane.comp.version-control.git@gnu.org>
URL: https://gitlist.dev/e/jwvlh6qt5i6.fsf-monnier%2Bgmane.comp.version-control.git%40gnu.org
In-Reply-To: <xmqqio4am3uk.fsf@gitster.mtv.corp.google.com>

```
>> I have a system here where it can be quite common to have thousands of
>> branches in the remote repository, and where I'd like to update some
>> local state according to the appearance of new branches (or updates of
>> pre-existing ones).
>> Currently, I use a "git for-each-ref" after pulling and then check (for
>> each one of those refs) if an update is warranted, but this can get slow
>> with that many branches.  Is there some way to get something like the
>> post-receive hook to be run for "git pull", so that the script gets told
>> directly which (remote tracking) branches have been modified/created?

> I do not think there is.  But you could easily script along the
> lines of...

>     #!/bin/sh
>     git for-each-ref | sort >prestate
>     git pull "$@"
>     git for-each-ref | sort >poststate
>     comm -12 prestate poststate

Right, it kinda works, but it can break down in case of
concurrent operations.

I really wish there was a way to get something like the post-receive
hook to be called everytime new commits are added, regardless if it's
due to a push, a pull, a commit, a fast-import, ...


        Stefan

```
