Skip to content

Instantly share code, notes, and snippets.

@andrewberls
Created October 22, 2014 19:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewberls/7bc712d8e57b370c8631 to your computer and use it in GitHub Desktop.
Save andrewberls/7bc712d8e57b370c8631 to your computer and use it in GitHub Desktop.
Prevent git pushes directly to master. Install to .git/hooks/pre-push
#!/bin/sh
# Pre-push hook to prevent pushes to master branch.
pushed_branch=`git rev-parse --abbrev-ref HEAD`
if [[ "$pushed_branch" == "master" ]]
then
echo "[Notice] Pre-push hook preventing push to master. Create a feature branch instead."
exit 1
fi
@elliot42
Copy link

Note that this needs chmod 700, and on my box, requires #!/bin/bash, not #!/bin/sh

Other than that works great, thank you for finding this!

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