How to prevent Merge and Commit for particular branch in Git ??

STEP 1 : Go to your repository in git

STEP 2: Create file .git/hooks/pre-commit with following content:

#!/bin/sh

branch="$(git rev-parse --abbrev-ref HEAD)"

if [ "$branch" = "master" ]; then
  echo "You can't commit directly to master branch"
  exit 1
fi

STEP 3: Make it executable (not required on Windows):

$ chmod +x .git/hooks/pre-commit


OPTIONAL:
 
To disable fast-forward merges you must also add following option to your .git/config file:

[branch "master"]
    mergeoptions = --no-ff


Post a Comment

0 Comments