タイトルは嘘。
リモートへのgit pushを禁ずるために、ローカルでmasterブランチにgit commitができないようにした。
以下を、gitレポジトリ内に配置すればよい。
.git/hooks/pre-commit
branch=`git symbolic-ref HEAD`
if test "$branch" = "refs/heads/master" || test "$branch" = "refs/heads/main"; then
echo "Direct commits to the master branch are not allowed."
exit 1
fi
executableにする。
$ chmod +x .git/hooks/pre-commit
すると、以下のようなエラーが出るようになった。
$ git commit -m 'test' --allow-empty
Direct commits to the master branch are not allowed.
よし。