Git hooks allows us to add functionality to Git by injected scripts in the control flow of Git.
In this case, we want to stop users from pushing to the master
branch.
You can look in the .git/hooks/
folder to see what hooks are available.
They are all named *.sample
to prevent them from being executed.
- run
source setup.sh
(or.\setup.ps1
in PowerShell)
- Put the
pre-push
hook into the hooks folder with the commandcp pre-push ./.git/hooks/pre-push
- What happens when you try to push to
master
? - What happens if you try to push to a different branch on the remote?
- What happens if you switch the if / else blocks in
./.git/hooks/pre-push
?