Git can be very convenient to keep your commit log clean. Here’s a way to install and share git hooks across your team when you are working in a hooks dockerized environment TL;DR: a demo project on github is available 1. Git hooks in a nutshell Git provides a way to run commands you do something. A common usage would be to run your linters before you try to commit something, for instance. If the linter detects any errors, then you are asked to fix it before you actually commit your work. This would typically clean your git log from commits such as . before “fixed lint” If you are new to this concept, you should at least know that: git hooks are script that are automatically found by git if present under the directory .git/hooks a git hook is run locally by your computer When a git hook fails, then your git command is not run. You might want to take a look at git samples that are already present in any git project: What you get after any `git init` Simply copy to make it executable, and here you are, you just installed your first working git hook ! pre-commit.sample pre-commit, 2. Using githooks as a team Now you probably know that if you put some scripts in your directory, then your teammates won’t be able to take advantage of it. You’re basically the only one to know about your script, and you can’t guarantee than any commit of your team passes the githook test you just wrote. .git/hooks Tools such as can help you to automatically install githooks when working directly with npm/yarn. But this is 2017 and we want to work with , don’t we ? husky docker Here’s what we are going to do: Create a directory at the root of the project, put some scripts inside, and commit them. hooks Create a docker container whose purpose is to create a symlink of the official hook script into your directory local .git/hooks Declare this container in your main docker-compose.yml. When anyone run the hook container will ensure that the official hooks are properly installed in your configuration. docker-compose up, Now let’s do this. First, we create a docker container, defined by some Dockerfile.githook: The idea behind this is quite simple. It basically creates a container that will: : go to some /tmp/hooks (explanations about this particular directory will come further), find scripts, and make them executable cd /tmp/hooks && ls | xargs chmod +x Now go to some dir, find the executables, and create symlinks to this directory cd /tmp/.git/hooks && find ../../hooks -type f -exec ln -sf {} /tmp/.git/hooks/\; /tmp/.git/hooks So this container is basically creating symlinks from its own to its own The last thing we need is to share our own and directories with the container. This way, when the container creates its own symlinks, then it will actually be doing this on our computer. Which is quite exactly what we are looking for. /tmp/hooks /tmp/.git/hooks. .git/hooks hooks This can be achieved by using volumes in your file: docker-compose.yml This will: declare a container in your main project. githook_installer use busybox: a tiny image that know about basic unix commands such as ls, xargs, find, ln... Mount your local directory into the container’s directory .git /tmp.git Mount your local directory into the container’s directory ./hooks /tmp/hooks boot everytime you run Note that this will actually create the symlinks every single time you run your project. But creating a bunch of symlinks that already exist is absolutely not an issue; you won’t even notice it. docker-compose up. 3. Now let’s have a demo, shall we ? I’ve created for those who are interested by the result a demo on github Let’s create a lunatic pre-commit script in the directory: ./hooks Now run as anyone would do when working with docker. docker-compose up, And try to commit something. You’ll either get: pre-commit hook startingOkay, I will accept your commitOn branch masternothing to commit, working directory clean Or pre-commit hook startingMeh. Maybe another time Not that if your commit is rejected, then the git log remains untouched. Perhaps you’ll want to write a more useful pre-hook now. could surely be a good idea, provided you created some container in your configuration ! docker-compose run linter linter