Even if this sentence usually applies to continuous integration, it is true as well for documentation.
Introducing the task of documenting the code into our workflow is the solution we found at OSEDEA to tackle that problem.

Most of the time, it might add 5-10 minutes to document a new feature, but it is such a big win on the lifetime of a project that you will definitely win it back as soon as another developer has to onboard the project.

That's why, to simplify our everyday lives as developers, a member of the team created a tool to allow us to write documentation using the command-line, and that's where git comes into play.

Using git to structure your workflow

Git is amazing. Any developer who knows or learns about git

It is amazing for a lot of reasons, but today, I'm going to talk about automating some processes in your workflow.

Git offers a set of hooks that you can customize to modify your workflow.

Let's look specifically at the pre-commit hook.

Pre-commit hook

First, take a repository that you would like to try out on and setup your hook.

I am not going to talk about it today, but know that the post-commit hook can be very useful as well, and works exactly the same way.

Global installation

As of git 1.7.1, you can set init.templatedir in your gitconfig to tell git where to look for templates.

Set it like this:

git config --global init.templatedir '~/.git_template'
Afterward, new repositories you create or clone will use this directory for templates. Place the hooks you want in ~/.git_template/hooks. Existing repositories can be reinitialized with the proper templates by running git init in the same directory .git is in.

For git versions older than 1.7.1, running git init --template ~/.git_template will work if you're like me and still want to manage your .git_template dir along with the rest of your dot files. You can also use the $GIT_TEMPLATE_DIR environment to tell git init where your template directory is.
Thank you, Stackoverflow Users! (source)

Move your pre-commit script into your newly created ~/.git_template/hooks folder and test out if git is getting it:

You should see your hook there, brought back by the git init, and it should be there by default in any new or cloned repository thereafter!

Conclusion

Git hooks are very powerful and I think they can be used to make everyone in the team more efficient.
You can do whatever you want in them, including, running your tests, your linter, etc.
Finally, if you need to push a really important fix in production right now and don't have the time to worry about documentation or linting, do not worry, you can always skips the hooks with git commit --no-verify.

I hope you liked this article, feel free to share it, comment below to give us feedback or kuddos. :)