I am hosting my code on Bitbucket. The webhooks are not adequate to solve my issue, so I am hoping git hooks will work. Since I don't imagine they will work server-side, the git hook should be propagated to each checkout on each developers machine. (I know this might be an issue since its normally a local file, but I can hopefully solve it using information from here)
I want to create a git hook that will push changes to staging branches.
Meaning, if I am a user named bob
and I want to push to production/master
, instead of it pushing to the production/master
branch it will push to a staging branch like staging/master/bob
. Same for another user roy
who pushes to production/master
it will go to staging/master/roy
. And the same for any production branch. So edd
pushing to production/2.0
would push to staging/2.0/edd
.
I have tried the pre-commit hook, but I can't find a way to direct the target of the push. I know this is possible.
I tried using GIT_WORK_TREE
, and I couldn't seem to get it to work.
Clarification
The whole process should be seamless for bob
the developer. He should pull from the master and push to the master. (or whatever branch he is working on) and the process will happen in the background. It will push his changes to a staging branch, which will then undergo a CI process, and if successful will be pushed into the main branch. This is the solution that I need.