Prevent commits in a local branch

前端 未结 1 1938
故里飘歌
故里飘歌 2020-12-15 20:19

In my local git tree I pull commits from the \"master\" branch in the repository, but all development is done in a different branch, and pushed in a different branch too.

相关标签:
1条回答
  • 2020-12-15 20:44

    You can use a pre-commit hook.

    For example, place the following script as .git/hooks/pre-commit:

    #!/bin/bash
    if test $(git rev-parse --abbrev-ref HEAD) = "master" ; then 
      echo "Cannot commit on master"
      exit 1
    fi
    

    And set it as executable

    chmod +x .git/hooks/pre-commit
    
    0 讨论(0)
提交回复
热议问题