In some CI setups special keywords might be used to trigger specific behavior in the pipeline. For example the CI pipelines might build feature branches if and only if the latest git commit message in a branch-push contains keywords like [build].
Even though this works the commit-messages become polluted with these keywords. So I was wondering whether it's possible to make some sort of local git-commit / git-push hook to automatically cleanup the latest git-commit message if it contains the [build] keyword a few seconds after the original commit message makes it across (to trigger the CI pipeline).
Here is the solution I came up with. Seems to be working fine based on my tests. Place this script as '.git/hooks/pre-push' and make sure to 'chmod +x .git/hooks/pre-push' too.
It detects whether the latest git-commit message contains the keyword [build] and if it does it pushes it across, waits for a few seconds (*), it amends the latest git-commit message to clean it up and it then carefully force-repushes the branch.
Feature branches cooperate very well with this technique even when multiple devs are working on them - it's highly unlikely that within that sensitive period of 3secs someone else will tweak the branch.
Note that technique is meant to be applied on feature branches - not the cornerstone branches and especially not 'master', 'main' or even 'develop'.