Skip to content

Instantly share code, notes, and snippets.

@miku
Last active August 29, 2015 14:05
Show Gist options
  • Save miku/b70499fff2b5c981b130 to your computer and use it in GitHub Desktop.
Save miku/b70499fff2b5c981b130 to your computer and use it in GitHub Desktop.
Suppress push of certain branch to a certain remote.
#!/usr/bin/env bash
# pre-push hook to prevent push of certain branches to github.com
# copy this file to .git/hooks/pre-push
# and make it +x
REMOTE="$1"
URL="$2"
CURRENT_BRANCH="$(git rev-parse --abbrev-ref HEAD)"
FORBIDDEN_BRANCH="private" # change this to your private branch ...
if [[ "$CURRENT_BRANCH" == "$FORBIDDEN_BRANCH" ]]; then
if [[ $URL =~ github.com ]]; then
cat <<EOF
XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX
Not allowed to push $FORBIDDEN_BRANCH on to github.
XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX
Please contact your admin for further assistance.
EOF
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment