Search⌘ K
AI Features

Hooking the Test into Git: Working of Git

Understand how to create and configure Git hooks such as pre-commit and pre-push scripts to automate testing workflows. Learn to enforce code quality by rejecting commits that fail checks and discover best practices for managing hook files in repositories.

Create scripts

Let’s make two simple scripts to show how git hooks work. The first one will be named .git/hooks/pre-commit. Do not include the .sample suffix or any other suffix. In the file, add these lines:

#!/usr/bin/env python
print('Hello from pre-commit')

Make a similar file with a different string and save it as .git/hooks/pre-push. Then make the files executable by entering the following command in the ...