0
0
Gitdevops~5 mins

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

Choose your learning style9 modes available
Recall & Review
beginner
What is a pre-push hook in Git?
A pre-push hook is a script that runs automatically before you push your changes to a remote repository. It can check your code or run tests to stop bad changes from being pushed.
Click to reveal answer
beginner
Where do you place a pre-push hook script in a Git project?
You place the pre-push hook script inside the .git/hooks/ folder of your project, and name it pre-push (no file extension).
Click to reveal answer
beginner
What must you do to make a pre-push hook script executable?
You must give the script execute permission using chmod +x .git/hooks/pre-push so Git can run it automatically.
Click to reveal answer
intermediate
What happens if a pre-push hook script exits with a non-zero status?
Git will stop the push process, preventing your changes from being sent to the remote repository.
Click to reveal answer
beginner
Give an example use case for a pre-push hook.
A pre-push hook can run automated tests or check code style before pushing. If tests fail, the push is stopped to keep the remote code clean.
Click to reveal answer
Where is the pre-push hook script located in a Git project?
A.git/pre-push
Broot/pre-push
C.git/hooks/pre-push
Dhooks/pre-push
What does a pre-push hook do if it exits with status 1?
AAllows the push
BStops the push
CDeletes the remote branch
DCreates a new commit
Which command makes a pre-push hook script executable?
Agit enable pre-push
Bgit hook activate pre-push
Cchmod 777 pre-push
Dchmod +x .git/hooks/pre-push
When does the pre-push hook run?
ABefore pushing changes to remote
BAfter pushing changes to remote
CBefore committing changes
DAfter merging branches
Which of these is a common use for a pre-push hook?
ARun tests before pushing
BCreate a new branch
CMerge branches automatically
DDelete local commits
Explain what a pre-push hook is and why it is useful.
Think about what happens right before you send your code to others.
You got /4 concepts.
    Describe the steps to create and enable a pre-push hook in a Git project.
    Focus on file location, permissions, and script behavior.
    You got /4 concepts.