Skip to content

Instantly share code, notes, and snippets.

@DanielArndt
Last active January 18, 2016 18:20
Show Gist options
  • Save DanielArndt/e220270e5ac8ee38083f to your computer and use it in GitHub Desktop.
Save DanielArndt/e220270e5ac8ee38083f to your computer and use it in GitHub Desktop.
#!/bin/bash
contains_element () {
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
protected_branches=("master" "develop")
# check each branch being pushed
while read local_ref local_sha remote_ref remote_sha
do
remote_branch=$(sed -e 's,refs/heads/\(.*\),\1,' <<< $remote_ref)
if contains_element $remote_branch ${protected_branches[@]} ;
then
echo "PUSH ABORTED: You are attempting to push directly to protected branch $remote_branch. Use --no-verify to force."
exit 1 # push will not execute
fi
done
exit 0
@DanielArndt
Copy link
Author

Put in .git/hooks/pre-push

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment