Skip to content

Instantly share code, notes, and snippets.

@nitanshu
Created July 18, 2017 09:22
Show Gist options
  • Save nitanshu/e50624f19d981a6422233543ae14b6b9 to your computer and use it in GitHub Desktop.
Save nitanshu/e50624f19d981a6422233543ae14b6b9 to your computer and use it in GitHub Desktop.
This is local pre-push the developer will not be allowed to push to that branch
# !/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. Copy the file into your repo at `.git/hooks/pre-push`
# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
# 3. Or, use `rake hooks:pre_push` to install
# Name a branch that you want to lock and no one will be able to push to this branch
protected_branch='branch_name'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
tput setaf 5; echo '***************************************************************************'
tput setaf 3; echo "Sorry you can't push to $protected_branch branch is locked."
tput setaf 5; echo '***************************************************************************'
exit 1 # push will not execute
else
exit 0 # push will execute
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment