post-receive hook to auto push the latest commit


I was going through learn how to add post-receive hook to automatically push the changes to live repo instead of doing git pull everytime. git pull also changes the owner of file to the user who is doing pull. our project directory is setup as follows.

chown -R wwwrun:developer project/

After pushing to bare repo we do pull to server root dirctory project/. This changes the ownership of file to username. With post-recieve hook the username will remain git. It is easy to change the user under which apache run so I can change that to git:developer. It will make life much easier and probabaly we wil lnever run into permission error as it happened in the past.

When I trie to edit post-recieve hook in stash-home repositiries I saw following message in post-recieve file

#!/usr/bin/env bash
if [[ "$OSTYPE" == "cygwin" ]]; then
    exec $(cygpath $STASH_HOOK_COORDINATOR) hooks/post-receive.d "$@" <&0 >&1 2>&2
    exec $STASH_HOOK_COORDINATOR hooks/post-receive.d "$@" <&0 >&1 2>&2

Where am I suppose to add post-recieve hook then? Can I create new file with any name and add hook code from above link? I am asuming stash go through post-receive.d directory for hook files.



1 answer

1 accepted

Hi Raminder,

You can add your own custom hooks to the pre-recieve.d and post-receive.d directories, and our scripts will execute them (in order).

Definitely don't modify those scripts - Stash depends on our own hooks to be notified of changes during a push. :)



Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jun 12, 2018 in Bitbucket

Do you use any Atlassian products for your personal projects?

After spinning my wheels trying to get organized enough to write a book for National Novel Writing Month (NaNoWriMo) I took my affinity for Atlassian products from my work life and decided to tr...

24,713 views 26 12
Join discussion

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