Skip to content

Instantly share code, notes, and snippets.

@5t111111
Last active October 13, 2016 06:32
Show Gist options
  • Select an option

  • Save 5t111111/be2f369a19502518e913 to your computer and use it in GitHub Desktop.

Select an option

Save 5t111111/be2f369a19502518e913 to your computer and use it in GitHub Desktop.
git pre-push hook to prevent direct pushing to master
#!/bin/sh
# An example hook script to prevent direct pushing to master
while read local_ref local_sha1 remote_ref remote_sha1
do
# If you also want to prevent direct pushing to branches in addition to master branch,
# just copy and paste the below and replace "master" with the branch name you desire.
# ==========> Copy & paste START
if [[ "${remote_ref##refs/heads/}" = "master" ]]; then
cat << EOT
============================================================
Pushing to the master branch is not allowed
============================================================
EOT
exit 1
fi
# <========== Copy & paste END
done
exit 0
@5t111111

5t111111 commented Nov 9, 2015

Copy link
Copy Markdown
Author
$ curl https://gist.githubusercontent.com/5t111111/be2f369a19502518e913/raw/8aa94a8f043a8ec3938e4c91c0ecd4d2bcfeac77/pre-push > .git/hooks/pre-push
$ chmod 755 .git/hooks/pre-push

this overwrites the existing pre-push

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