3


I have a case where I need to create a post-receive hook under $REPO_NAME/.git/hooks/post-receive.
What I'm trying to do is to make this file $REPO_NAME/.git/hooks/post-receive part of my repository and can be cloned as well.

I need to make this file exist and available to be used by any user clone my repo. I tried to commit and push it but it's failed since .git dir is ignored by default by Git

[$MY_REPO/.git/hooks]>git add post-receive
fatal: this operation must be run in a work tree

Any idea/workaround about how to resolve this issue.

Note: I know I can use github webhook but I need to do some customized process so that I need to use git web hook.

Appreciate your help

Saleh Ibrahim
  • 57
  • 1
  • 8

1 Answers1

2

as per this documentation https://www.atlassian.com/git/tutorials/git-hooks

Maintaining hooks for a team of developers can be a little tricky because the .git/hooks directory isn’t cloned with the rest of your project, nor is it under version control. A simple solution to both of these problems is to store your hooks in the actual project directory (above the .git directory). This lets you edit them like any other version-controlled file. To install the hook, you can either create a symlink to it in .git/hooks, or you can simply copy and paste it into the .git/hooks directory whenever the hook is updated.

i think the best way is to create a directory with the hooks in the repo and link it to the .git folder

all you have to do is to link the scripts on each clone

i don't think there is any other way