Every product that is developed by more than one programmer needs to have some guidelines to harmonize the workflow.
A standardized software development workflow between programmers allows, for example:
- faster engineering, since each developer can rely on a habitual activity
- fewer errors, as the workflow itself shall be structured in a way to avoid some mistakes
- easy integration of new members
- improved log of history
One very easy to use feature are “Githooks”(if you are using Git for version control).
In this article I want to show how easy it actually is to set up a few workflow guidelines with Githooks. This will allow your team to be on one page when developing software.
Table of Contents
- Why Githooks?
- GitFlow and Checkout, Commit, Push
- “Enforce” the hooks
- Fix one common problem
Githooks are, as the word suggests, a hook for Git commands. Intuitively this makes sense. With Git you are essentially managing the workflow of a piece of software. Every Branch is a part of the whole piece. Every Commit is a building block of a Branch.
So in order to standardize quality in software development, one must standardize actions in the building process of the product.
There are many Git commands that can be hooked for setting standards. Remember, there are quite a few:
To establish an improved workflow you don’t have to use all of them. Focus on the few important ones. In my experience so far, those are:
Let me explain why.
GitFlow and Checkout, Commit, Push
Using Git as version control system allows to set a workflow. I do this using the GitFlow method.
It is basically to develop a piece of software where each feature is represented by a branch.
In the following examples I will always check naming with Regex tests or execute another script.
The increased importance of a branch allows for the first hook on “post-checkout”. It is triggered after a new branch is created with Git.
Often a naming convention is applied to make branches comparable and understand their use for the whole product.
You can create a simple shell script like this to ensure naming:
In web development there are multiple libraries that help with setting up a hook for committing. Often they are not necessary, as simple scripts can be written by yourself as well.
See validation of a git message for example:
“Git push” is the process of “sharing” your branch with the team. It is often the last step before opening a pull-request for a merge with the main branch.
This is a good time to check other guidelines like “linting” of the code, or if all tests are passing.
An example for executing another script could be:
“Enforce” the hooks
Another step is to actually enforce those hooks.
Create your own install script! Like:
Fix one common problem
One issue that kept me guessing for a while was that Git hooks are NOT executable by default. This means that they need to be made executable with
chmod +x <pathToHook>
See StackOverflow discussion here.
I hope that this will help some of you to align the workflow of your development team and make everyone’s lives much easier. :-)
Thanks for reading my article! Feel free to leave any feedback!