Git のフック機能(pre-push)を使い、対象のブランチ(例: csv-history)が push されそうになったときに自動でエラーを出して処理をキャンセルする方法。

.git/hooks/pre-push に以下のスクリプトを配置することで、対象ブランチへの push を禁止することができます。

#!/bin/sh

protected_branch="history"
current_branch=$(git symbolic-ref --short HEAD)

if [ "$current_branch" = "$protected_branch" ]; then
  echo "You are trying to push to the protected branch '$protected_branch'."
  echo "Please switch to a different branch before pushing."
  exit 1
fi

exit 0

面倒な場合は以下のコマンドで直接フックを作成することもできます。

cat << 'EOF' > .git/hooks/pre-push
#!/bin/sh

protected_branch="history"
current_branch=$(git symbolic-ref --short HEAD)

if [ "$current_branch" = "$protected_branch" ]; then
  echo "You are trying to push to the protected branch '$protected_branch'."
  echo "Please switch to a different branch before pushing."
  exit 1
fi

exit 0
EOF

echo の部分を日本語にしたいなら、

echo "保護されたブランチ '$protected_branch' に push しようとしています。"
echo "push する前に別のブランチに切り替えてください。"

と書き換えれば OK です。

ちなみに、pre-push は実行可能にしておく必要があります。

chmod +x .git/hooks/pre-push

なお、.git/hooks 配下のファイルは Git 管理対象ではないので、個人の環境ごとに設定する前提です。チーム全体で統一したルールにしたい場合は、pre-push をテンプレート化したり、CI 側での保護チェックを併用するとよいです。