# WebHook creation and using

**URL:** <https://forum.gitea.com/t/webhook-creation-and-using/5453>\
**Category:** Install/Maintain/Configure\
**Created:** [July 6, 2022, 6:17pm UTC](https://forum.gitea.com/t/webhook-creation-and-using/5453 "2022-07-06T18:17:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Viacheslav](https://avatars.discourse-cdn.com/v4/letter/v/f07891/32.png) [@Viacheslav](https://forum.gitea.com/u/Viacheslav)\
**Post date:** [July 6, 2022, 6:18pm UTC](https://forum.gitea.com/t/webhook-creation-and-using/5453/1 "2022-07-06T18:18:00Z")

</div>

I am completely newbie here, so sorry for primitive question.  
Gitea is working fine, i need to set up a simple hook to prevent commits on main branch.  
I set up a webhook see pic.1

 ![Pic1](https://us1.discourse-cdn.com/flex020/uploads/gitea/original/2X/9/908556ec61cef14bc98bdf0d1cc266c950b892c5.png)

I have a response from Test Delivery, see pic.2

 ![Pic2](https://us1.discourse-cdn.com/flex020/uploads/gitea/original/2X/a/a5b049a85a8424b85f76275c7aaa32683321762f.png)

But where to put webhook.php file?  
I put it in the root but its not fired, see pic.3.

 ![Pic3](https://us1.discourse-cdn.com/flex020/uploads/gitea/original/2X/2/213cecacc3bd11735643c6aea1871dba51e399ad.png)

Here is the content of the webhook.php (took from stackoverflow):

#!/bin/sh

branch=“$(git rev-parse --abbrev-ref HEAD)”

if [“$branch” = “main”]; then  
echo “You can’t commit directly to main branch”  
exit 1  
fi

I tried to look through forum here, read around 30 topic about webhooks, looks like it too simple question to ask but same time i dint find anything on documentation.

This was not enough for me [Webhooks - Docs](https://docs.gitea.io/en-us/webhooks/)

Please, help.

---

<div class="post-metadata">

**Author:** ![DaveArchetype](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/davearchetype/32/6207_2.png) [@DaveArchetype](https://forum.gitea.com/u/DaveArchetype)\
**Post date:** [August 30, 2024, 12:36pm UTC](https://forum.gitea.com/t/webhook-creation-and-using/5453/2 "2024-08-30T12:36:31Z")

</div>

Hey, late reply, I know, but I assume the webhook.php is just simulating a server.  
You would have your own API which will wait for the POST request, then do something with the information it receives. Maybe you will want to trigger a CI/CD by pulling the latest commit and restarting your service.
