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

2 Comments

  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

    ReplyDelete
  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

    ReplyDelete