What are Git hooks?
Git hooks are scripts you execute before an action is performed. It can be
pre-rebase. Often, developers use them to perform
some checks on the commit being pushed, either on the commit title, message
or the code itself.
Why using hooks with Codiga?
Using hooks with Codiga, you can check your code before pushing it. You invoke Codiga to check your code on what has been modified.
It shows you all errors before you push your code and send it for review. That way, no error or warnings are triggered by Codiga during the Code Review since you checked everything before pushing the code! In other words, it helps you doing faster code reviews.
The first step is to install our
that is distributed in the
codiga Python package. To install it,
just run the following command:
pip install codiga
In order to use the tool, you need to define the following variables:
CODIGA_API_TOKEN: your API token
These API keys are available in your API tokens.
Configure your Git hooks
You need to add a script in your Git repository to integrate with Codiga and check for violations at each push.
.git/hooks/pre-push in your Git repository and make sure
to make it executable (
chmod a+x .git/hooks/pre-push).
The tool is invoked with the local and remote SHA. It also needs the name
of the corresponding project on Codiga (the argument
<project-name> with the name of your project on Codiga so that
it will filter violations according to your project configuration.
while read local_ref local_sha remote_ref remote_sha
codiga-pre-hook-check --project-name "<project-name>" --remote-sha $remote_sha --local-sha $local_sha
if [ "$?" -ne "0" ]; then
echo "Codiga found errors"
You can use some additional options with
codiga-pre-hook-check to filter
some violations or categories.
--exclude-categories: exclude categories of violations. Separate multiple categories using a comma. For example
--exclude-categories=Performance,Code_Style,Designwill reports all issues in the code being pushed but the one that are classified under the performance, code style or design categories.
--exclude-severities: exclude categories of severities. Separate severities are specified using a comma. Severities are specified by number, 4 being the lowest and 1 the highest severity. The option
--exclude-severities=3,4reports all violations but the one with the severity 3 and 4.
When using the
pre-push script, your code is being sent to the Codiga
servers for analysis. The analysis is not local, it is done directly
on Codiga servers to avoid any load on your local machine.
If you have any issue with the
pre-push script, please open
an issue on our GitHub project.