Just had a fun moment where I didn't realise I was on the master branch of repo and was able to force push after a rebase (a dance I'm so used to during development I do it almost without thinking). If you're like me and don't want that to happen to you you can set up a safe guard to stop you ever being able to push to master. What you need in your life is a simple git hook. Here are the steps to create your own if you want
Tell git where to find your templates for new repos:
> git config --global init.templatedir $HOME/.git_templateNext, create that directory with a hooks directory inside it
> mkdir -p $HOME/.git_template/hooksNext cd into that hooks directory and create a pre-push file, be sure to make it executable
> cd $HOME/.git_template/hooks
> touch pre-push
> chmod ug+x pre-pushopen up the pre-push file in your favourite editor and add this code
#!/bin/sh
branch=$(git rev-parse --abbrev-ref HEAD)
if [ branch = "master" ]; then
echo "Can't push to master" >&2
exit 1
fiNow anytime you initialise a repo git will place this in the hooks folder of the repo, and it will run this file before it pushes some changes. You can add this to repos you have already got on your local but running git init inside them but beware it will overwrite any hooks already set up in that repo.