branch_name=$(git rev-parse --abbrev-ref HEAD) if [ "$branch_name" = "deployment" ]; then echo"You are not allowed to push the 'deployment' branch." exit 1 fi
執行以下指令,讓腳本可以被執行。
1
chmod +x .git/hooks/pre-push
當嘗試推送 deployment 分支時,系統會顯示錯誤訊息,並且推送將被阻止。
1 2 3 4
git push --set-upstream origin deployment
You are not allowed to push the 'deployment' branch. error: failed to push some refs to 'github.com:memochou1993/blog.git'