4

I'd like to add a git hook to a project of mine. I have created it (.git/hooks/pre-push) and it works locally.

Now how can I include it to the repo so when I push the project to GitHub other people can get the hook upon cloning the repo?

Even if I do not have a .gitignore file the .git folder is automatically ignored

Thanks

Sig
  • 5,476
  • 10
  • 49
  • 89

1 Answers1

4

The directory .git/hooks is not part of your working directory and therefore is not committed nor pushed to the repo.

What you can do is to create (in your working directory) shell script file that will create the needed hooks and then ask the other developers or users to execute the file and create the hooks.

Additionally GitHub and Bitbucket and similar allow you to create web hooks that trigger at certain conditions. Here you can read more about the web hooks : https://developer.github.com/webhooks/

Update

If you are using Bitbucket even in the free service there is a feature to set permissions which user can push to which branch. Check limit the push powers

My usual approach is to create separate branch for each developer or company and to allow them to push only in their own branch. Then the project manager or the lead developer can decide which branch when to merge into the master.
This way the code is very easily manageable.

Update2

GitHub is lacking some of the features of Bitbucket, but in this case the same type of control can be achieved if you ask all the developers to fork the repo, then work in their own forked repos and once ready to create pull requests so the project manager or the lead developer can review and merge the repos or create issues to be fixed.

This is known as fork and pull GitHub model, here you can read more about it: https://help.github.com/articles/using-pull-requests/#fork--pull

Community
  • 1
  • 1
Antoan Milkov
  • 2,152
  • 17
  • 30
  • Thanks for your reply. GH web-hooks is not what I'm looking for since I need to prevent pushing to specific branches. The solution you suggested leaves the developers the ability not to create the hook so it doesn't really solve my issue. I will keep looking for anything. – Sig Nov 06 '14 at 04:58
  • Thanks for the update. However, we use GitHub and we are very happy with it so I don't plan to switch to BitBucker anytime soon. – Sig Nov 06 '14 at 09:30
  • @macsig Second update – Antoan Milkov Nov 07 '14 at 07:11
  • Thanks for the reply. I have decided to go with git hooks and a shell script that symlinks them. – Sig Nov 07 '14 at 09:21