Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
protect master branch
protect_branch() {
current_name=$(git symbolic-ref HEAD | sed -e "s/^refs\/heads\///")
if [ "$current_name" = "$protected_name" ]; then
echo "!!! OH NO! you are trying to change the **$protected_name** branch!!!"
exit 1
protect_branch master
Copy link

mozillazg commented May 1, 2016

$ cat pre-commit >> .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
cat pre-commit >> .git/hooks/pre-push
chmod +x .git/hooks/pre-push

$ git branch
* master
$ git commit -am "test"
!!! OH NO! you are trying to change the **master** branch !!!
$ git checkout test
A   a.tste
Switched to branch 'test'
$ git commit -am "test"
[test 6201659] test
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.tste

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment