threads / discuss / 18505

git hooks to run something

Subject: git hooks to run something

## tl;dr

3 messages between Mar 24, 2009 and Mar 25, 2009.

replies: 2people: 2as markdown or json

Alf Clement· Mar 24, 2009, 10:56 UTC · lore
Hi all,

when I switch between branches, I would like like to delete some object files and prepare some setup files. I there a good way to do this automatically when I run "git checkout branch", like misusing a hook to run a make in a special directory? All would happen in my local repository.

Thanks, Alf

Jeff King· Mar 24, 2009, 11:15 UTC · re: Alf Clement · lore

Re: git hooks to run something

On Tue, Mar 24, 2009 at 11:56:05AM +0100, Alf Clement wrote:
Show 6 quoted lines
> when I switch between branches, I would like like to delete some
> object files and prepare some setup files.
> I there a good way to do this automatically when I run "git checkout
> branch", like
> misusing a hook to run a make in a special directory?
> All would happen in my local repository.
There is a post-checkout hook; see "git help hooks" for details.

You could also make an alias; see the documentation for "alias.*" in "git help config".

-Peff
Jeff King· Mar 25, 2009, 11:25 UTC · lore

Re: git hooks to run something

[re-adding git@vger to cc; please keep questions on-list so that others can also help to answer]

On Wed, Mar 25, 2009 at 11:33:39AM +0100, Alf Clement wrote:
> is there a way to push a modified hook script with the repository when
> I push it to a server?
> And how to get it with pull?

No; for security reasons, no code (including hooks) from remote repositories is automatically run. The usual method is to include the hook in your repository and copy it into place after cloning.

-Peff

← back to recent threads