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 .git/hooks/*
directory.
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
.git/hooks/pre-hook
file - 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
git push
- (Optional) If you want this hook in all git projects by default, try out git templating.
The code:
Previous: Master's Thesis: On The Link Between Mobile App Quality And User Reviews
Next: Automatically run Rails database migration after deploying to Heroku