--- title: マスターブランチでのコミットを禁止するpre-commitスクリプト author: kazu634 date: 2013-03-16 url: /2013/03/16/do-not-commit-on-master-branch/ has_been_twittered: - yes tmac_last_id: - 331192087183753216 categories: - git --- Gitを使っていてマスターブランチでのコミットを禁止したい場合の pre-commit スクリプトのサンプルです:
#!/bin/sh
# if the branch is master, then fail.
branch="$(git symbolic-ref HEAD 2>/dev/null)" || \
"$(git describe --contains --all HEAD)"
if [ "${branch##refs/heads/}" = "master" ]; then
echo "Do not commit on the master branch!"
exit 1
fi
git initを実行した際には、/usr/share/git-core/templates/hooks/ 配下から${GIT_DIR}/.git/hooksにコピーされるそうです。共通のスクリプトとして /usr/share/git-core/templates/hooks/ に格納してしまうのもありかもしれないと思いました。
## 参考
* 参考にさせていただいたスクリプト
* 多人数開発で Git を使う場合の環境構築