0
0
Gitdevops~5 mins

pre-commit hook in Git - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ATo delete old commits
BTo merge branches automatically
CTo push changes to remote
DTo run checks before saving a commit
Where is the pre-commit hook script located in a Git project?
Aconfig/pre-commit
Broot/pre-commit
C.git/hooks/pre-commit
Dsrc/hooks/pre-commit
What happens if a pre-commit hook script fails (exits with error)?
ACommit is stopped
BCommit proceeds anyway
CGit deletes the commit
DGit pushes the commit automatically
Which command makes a pre-commit hook script executable on Unix?
Agit enable pre-commit
Bchmod +x .git/hooks/pre-commit
Cchmod 777 pre-commit
Dgit hook activate pre-commit
Which of these is a common use for a pre-commit hook?
ACheck code style before commit
BAutomatically merge branches
CCreate new branches
DDelete remote branches
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.