45

I've looked around the answers on SO, and the web, and I can't see anything on how to set up a server-side git hook on github (as opposed to webhooks). Is there a way to do this?

Or alternatively, is there a way to set it up so that .git/hooks is a symlink to a part of the working tree at the time of cloning?

I should add that this is an internally-hosted github server.

Marcin
  • 48,559
  • 18
  • 128
  • 201

1 Answers1

33

For obvious reasons, GitHub won’t allow you to execute arbitrary code on their servers as part of Git hooks. The only hooking they allow is through their webhooks or the integrated third-party services.

If you need to run some custom code, you will have to host that somewhere and set up a webhook to run it on your own server.

poke
  • 369,085
  • 72
  • 557
  • 602
  • 3
    OK, but what if I have my own github server? And what about changing .git/hooks in the repo? – Marcin Feb 28 '14 at 16:34
  • 3
    You mean GitHub Enterprise? See [this question](http://stackoverflow.com/questions/12188798/githubenterprise-post-receive-hook). – poke Feb 28 '14 at 16:36
  • 2
    I mean I wouldn't say it's obvious but definitely good to know. – dtc Mar 20 '21 at 19:09
  • 3
    It's not obvious particularly given that GitHub Actions allows arbitrary code executions. The difference is Actions run within VMs. There's no reason why server-side hooks couldn't be run within containers or k8s pods. I would say it's GitHub's decision not to support this. – coder.in.me May 07 '22 at 09:56
  • It's _obvious_ the answer was not _obvious_ as it is now (7 years later) wrong. Even then though virtualization was already ubiquitous so the question was very reasonable and the not obvious. – Samuel Neff Jul 06 '22 at 02:05