Recall & Review
beginner
What is a pre-commit hook in Git?
A pre-commit hook is a script that runs automatically before a commit is saved. It helps check or change files to keep code quality before saving changes.
Click to reveal answer
beginner
Where do you place a pre-commit hook script in a Git project?
You place the pre-commit hook script inside the
.git/hooks/ folder of your project, naming it pre-commit and making it executable.Click to reveal answer
intermediate
What happens if a pre-commit hook script exits with a non-zero status?
Git stops the commit process and shows the error. This prevents bad or unwanted changes from being saved.
Click to reveal answer
beginner
Give an example of a simple pre-commit hook use case.
A pre-commit hook can check if code files have no syntax errors or if commit messages follow a style guide before allowing the commit.
Click to reveal answer
beginner
How can you make a pre-commit hook script executable on Unix systems?
Run the command
chmod +x .git/hooks/pre-commit to give execute permission to the script.Click to reveal answer
What is the main purpose of a pre-commit hook in Git?
✗ Incorrect
A pre-commit hook runs scripts before a commit is saved to check or modify files.
Where is the pre-commit hook script located in a Git project?
✗ Incorrect
Git looks for hook scripts inside the .git/hooks directory.
What happens if a pre-commit hook script fails (exits with error)?
✗ Incorrect
A failing pre-commit hook stops the commit to prevent bad changes.
Which command makes a pre-commit hook script executable on Unix?
✗ Incorrect
chmod +x sets execute permission needed for the hook script to run.
Which of these is a common use for a pre-commit hook?
✗ Incorrect
Pre-commit hooks often check code style or run tests before committing.
Explain what a pre-commit hook is and why it is useful in Git.
Think about what happens before you save your work in Git.
You got /4 concepts.
Describe the steps to create and enable a simple pre-commit hook script in a Git project.
Focus on file location, permissions, and testing.
You got /4 concepts.