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:


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

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

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

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

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

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

Post a Comment


  1. Fantastic!! you are doing good job! I impressed. Many bodies are follow to you and try to some new.. After read your comments I feel; Its very interesting and every guys sahre with you own works. Great!!

    giá vé máy bay từ vietnam đi anh

    cách mua vé máy bay đi mỹ giá rẻ

    vé máy bay giá rẻ đi thái lan nok air

    vé máy bay đi malaysia vietjet

    vé máy bay đi singapore từ đà nẵng

  2. Actually I read it yesterday I looked at most of your posts but I had some ideas about it . This article is probably where I got the most useful information for my research and today I wanted to read it again because it is so well written.
    Data Science Course in Bangalore

  3. I am browsing the website daily, and get good facts from here all the time... visa required for Turkey, the visa fee depends on how quickly you want to process your application. Here you can read all the details about Turkey visa eligibility rules, visa exemption guidelines, passenger locator form & visa fees. Visit Turkey evisa portal.