# Intro # Gitlint is a git commit message linter written in python: it checks your commit messages for style. Great for use as a [commit-msg git hook](#using-gitlint-as-a-commit-msg-hook) or as part of your gating script in a [CI pipeline (e.g. Jenkins)](index.md#using-gitlint-in-a-ci-environment). !!! note Gitlint is not the only git commit message linter out there, if you are looking for an alternative written in a different language, have a look at [fit-commit](https://github.com/m1foley/fit-commit) (Ruby) or [node-commit-msg](https://github.com/clns/node-commit-msg) (Node.js). ## Features ## - **Commit message hook**: [Auto-trigger validations against new commit message right when you're committing](#using-gitlint-as-a-commit-msg-hook). - **Easily integrated**: Gitlint will validate any git commit message you give it via standard input. Perfect for [integration with your own scripts or CI system](#using-gitlint-in-a-ci-environment). - **Sane defaults:** Many of gitlint's validations are based on [well-known](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html), [community](http://addamhardy.com/blog/2013/06/05/good-commit-messages-and-enforcing-them-with-git-hooks/), [standards](http://chris.beams.io/posts/git-commit/), others are based on checks that we've found useful throughout the years. - **Easily configurable:** Gitlint has sane defaults, but [you can also easily customize it to your own liking](configuration.md). - **User-defined Rules:** Want to do more then what gitlint offers out of the box? Write your own [user defined rules](user_defined_rules.md). - **Broad python version support:** Gitlint supports python versions 2.6, 2.7, 3.3+ and PyPy2. - **Full unicode support:** Lint your Russian, Chinese or Emoji commit messages with ease! - **Production-ready:** Gitlint checks a lot of the boxes you're looking for: high unit test coverage, integration tests, python code standards (pep8, pylint), good documentation, proven track record. ## Getting Started ## ```bash # Install gitlint pip install gitlint # Check the last commit message gitlint # Alternatively, pipe a commit message to gitlint: cat examples/commit-message-1 | gitlint # or git log -1 --pretty=%B | gitlint # Or read the commit-msg from a file, like so: gitlint --msg-filename examples/commit-message-2 # To install a gitlint as a commit-msg git hook: gitlint install-hook ``` Output example: ```bash $ cat examples/commit-message-2 | gitlint 1: T1 Title exceeds max length (134>80): "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping " 1: T2 Title has trailing whitespace: "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping " 1: T4 Title contains hard tab characters (\t): "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping " 2: B4 Second line is not empty: "This line should not contain text" 3: B1 Line exceeds max length (125>80): "Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120. " 3: B2 Line has trailing whitespace: "Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120. " 3: B3 Line contains hard tab characters (\t): "Lines typically need to have a max length, meaning that they can't exceed a preset number of characters, usually 80 or 120. " ``` !!! note The returned exit code equals the number of errors found. [Some exit codes are special](index.md#exit-codes). For a list of available rules and their configuration options, have a look at the [Rules](rules.md) page. The [Configuration](configuration.md) page explains how you can modify gitlint's runtime behavior via command-line flags, a ```.gitlint``` configuration file or on a per commit basis. As a simple example, you can modify gitlint's verbosity using the ```-v``` flag, like so: ```bash $ cat examples/commit-message-2 | gitlint -v 1: T1 1: T2 [removed output] $ cat examples/commit-message-2 | gitlint -vv 1: T1 Title exceeds max length (134>80) 1: T2 Title has trailing whitespace 1: T4 Title contains hard tab characters (\t) [removed output] $ cat examples/commit-message-2 | gitlint -vvv 1: T1 Title exceeds max length (134>80): "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping " 1: T2 Title has trailing whitespace: "This is the title of a commit message that is over 80 characters and contains hard tabs and trailing whitespace and the word wiping " [removed output] ``` The default verbosity is ```-vvv```. Other commands and variations: ```no-highlight $ gitlint --help Usage: gitlint [OPTIONS] COMMAND [ARGS]... Git lint tool, checks your git commit messages for styling issues Options: --target DIRECTORY Path of the target git repository. [default: current working directory] -C, --config PATH Config file location [default: .gitlint] -c TEXT Config flags in format .