How to chain multiple git hooks with bash

If you spend any amount of time with git hooks, you learn pretty quickly that There Can Be Only One. Git doesn’t provide a way to call multiple scripts from a single hook.

Don’t get me wrong. I’m not complaining about any lack of functionality. In fact I think it’s a great example of clearly defined scope. Git provides a basic hook mechanism. What you do with it is your business. End of story.

Still, the problem you eventually run in to is that you either have to choose between which 3rd party hook script you require more, or you need to try to lace multiple scripts together into a single file. This can be tough if you’re not familiar with the language used in the hook script, or even worse, if the two scripts you need to combine are written in different languages.

But with a little bit of bash and some cleverly placed symlinks, you can run as many pre-receive, post-receive, or whatever type of hook scripts you need. This allows hooks from different authors in different languages to co-exist peacefully and independently.  It also allows you to keep your hook scripts small and dedicated to a particular purpose, which can in turn make them highly reusable.

This article will get you up and running with what’s called Hook Chaining in less than 10 minutes.
Continue reading How to chain multiple git hooks with bash