HostOnNet Blog

GIT Disable accidental commit on master branch

Looking for Linux Server Admin or WordPress Expert? We can help.

To disable accidental commit on master branch, create file

vi .git/hooks/pre-commit

In your git repository root directory with following content

#!/bin/sh

BRANCH=`git rev-parse --abbrev-ref HEAD`

if [ "$BRANCH" = "master" ]
then
    echo "DO NOT COMMIT ON MASTER BRANCH. CREATE YOUR OWN BRANCH AND COMMIT"
    exit 1
fi

exit 0

Make this file executable

chmod 755 .git/hooks/pre-commit

Now commit on master branch won’t be allowed.

Posted in Git

One Response to GIT Disable accidental commit on master branch

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.