masterブランチにpushさせないようにするフック
git push -f origin master
をして「master
ブランチがあああああ、あっあっあっ」とならないために(今日なった)
$HOME/.git_template/hooks
というディレクトリをつくる
$ mkdir -p ~/.git_template/hooks
作成したディレクトリにpre-push
というファイルを作る
$ emacs ~/.git_template/hooks/pre-push
pre-push
#!/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 push on the master branch!" exit 1 fi
作ったあとは実行権限を与えます
$ chmod +x ~/.git_template/hooks
.gitconfig
に設定を追加する
$ git config --global init.templatedir ~/.git_template/
以上で次からクローンしてくるリポジトリにはgit push origin master
ができなくなります
今既に存在しているリポジトリでもマスターへのプッシュを禁止したいときはレポジトリの.git/hooks
ディレクトリに追加するといいです
$ cd repo
$ cp ~/.git_template/hooks/pre-push ./git/hook/pre-push
参考に書いてあることをそのままコピーしただけなので参考を見てください