HostOnNet Blog


GIT Disable accidental commit on master branch

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

  • Hostonnet

    This is very helpful.

    Thanks,