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

参考に書いてあることをそのままコピーしただけなので参考を見てください

参考

masterのpushを常に禁止する