I have heard horror stories about developers accidentally force pushing to the master branch of their project. This can be very difficult to revert, but luckily this can be avoided using a Git pre-push hook.
A pre-push hook is just a script that lives in the
It is run every time you push to your Git repository. I have edited the script
to prompt you for a confirmation before you push to the master branch.
Are you sure you want to push to "master" ? (y/n):
To get this to work:
- Add the code below to you project’s
- Make the script executable with
chmod +x .git/hooks/pre-hook
- Try this out my making a minor change in one of the directories above and
- (Optional) If you want this hook in all git projects by default, try out git templating.