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.

I would like to avoid mistakes and prevent accidental commits in my local "master" branch, and allow only pull requests (then I'd rebase the developement branch to the updated master). Is this possible? How?

4

1 回答 1

31

您可以使用预提交挂钩

例如,将以下脚本放置为.git/hooks/pre-commit

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

并将其设置为可执行文件

chmod +x .git/hooks/pre-commit
于 2013-06-25T09:43:07.913 回答