Skip to content
Learn Netverks

Lesson

Step 27/36 75% through track

git-hooks-bash

Git hooks with Bash

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Git hooks with Bash: the syntax, patterns, and safety habits you need before advancing in Bash.

Teams still ship Git hooks with Bash in Bash codebases—skipping it leaves gaps in debugging and code reviews.

You will apply Git hooks with Bash in contexts like: Remote server maintenance, pre-commit checks, and deploy hooks.

Read each lesson, copy bash examples into your own terminal, and complete the lesson MCQs—there is no in-browser runner for security reasons.

When you can explain the previous lesson's ideas without copying starter code.

Git hooks are scripts Git runs at events (pre-commit, pre-push). They are almost always Bash or sh-compatible—tie directly to the Git track.

Sample pre-commit

#!/usr/bin/env bash
set -e
if grep -R "FIXME" --include="*.py" .; then
  echo "Remove FIXME before commit" >&2
  exit 1
fi
echo "pre-commit ok"

Place in .git/hooks/pre-commit and chmod +x—or use a hook manager like pre-commit framework.

pre-push smoke test

#!/usr/bin/env bash
npm test   # example; replace with project command

Keep hooks fast—slow hooks get skipped with --no-verify, defeating the purpose.

Sharing hooks

Version hooks under scripts/hooks/ and document install steps—.git/hooks is not cloned. Teams symlink or copy on setup.

Important interview questions and answers

  1. Q: Where do hooks live?
    A: In .git/hooks/ with executable names matching hook names.
  2. Q: exit 1 in a hook?
    A: Aborts the Git operation (commit/push) with an error message.

Self-check

  1. What filename blocks commits in the example?
  2. Why keep hooks fast?

Tip: Version hook scripts in scripts/; .git/hooks is not cloned.

Interview prep

Hook location?

.git/hooks with executable name.

exit 1 in hook?

Aborts the Git operation with failure.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • pre-commit lint?
  • hook not running?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump