Use GIT Hooks with stash?

Is it possible to use GIT hooks in .git/hooks/ with Stash?

It would like to know if I can write a simple shell script for the post-receive hook to be run by the server on a git push. It should check out a branch to a webserver.

I was not able to find a word on this anywhere.

Thanks in advance, regards from munich


2 answers

1 accepted

This widget could not be displayed.

Hi Jochen,

You can use standard git hook scripts with Stash (in addition to Java-based hooks). Just pop them in the <STASH_HOME>/data/repositories/<repo-id>/hooks/post-receive.d directory.



Thx! I will give it a try!



Sorry for butting there more in depth documentation on this subject somewhere?

Some specific questions off the top of my head:

  1. Is there any location where I can place standard git hook scripts so they automatically get placed in (post|pre)-receive.d when new repos get created?
    (Yes, Java based hooks are nice, but I have a few Perl hooks I can't discard at the moment).

  2. Can I on a global/project level mandate the use of one or more (Java based) hooks for 'all' repos (or 'all' in a given project). As a sysadmin mandate, can I protect them from being disabled for certain repos?

  3. Is there any UI to allow me to simply work with hooks for a set of repos, i.e. looking at a list of 133 repos, I'd like to check 57 and then 'enable hook X for all checked'.

I can probably work around things in various ways, but in case there are existing ways to achieve them, it'd be nice(r)...



This widget could not be displayed.

Hi Kenneth,

There isn't really any documentation about managing raw Git hooks, possibly because it's not necessarily something Stash wants to encourage.

1. I believe you should be able to add them to the global Git templates directory, which is used when new Git repositories are created in Stash. I would recommend using symlinks to the actual script so that when the file is _copied_ it will be a copy of the symlink and not the actual file (which will then get out of sync).

2. Not at the moment. This is something that's a more general problem for most of the repository settings, not just hooks. This might be a good feature request to follow:

3. Again, not at the moment. Your best bet would be to use our REST api from a local script:



Thanks Charles, I'll investigate.

One thing I forgot to mention - if you do create the templates in the global templates directory make sure you add them to pre-receive.d or post-receive.d, otherwise they won't work.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 21, 2018 in Bitbucket

Branch Management with Bitbucket

As a project manager, I have discovered that different developers want to bring their previous branching method with them when they join the team. Some developers are used to performing individual wo...

1,207 views 8 11
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you