Skip to content

Instantly share code, notes, and snippets.

@bozdoz
Created July 10, 2018 18:30
Show Gist options
  • Save bozdoz/a4ad1b72f670aa213d046cf62936f32c to your computer and use it in GitHub Desktop.
Save bozdoz/a4ad1b72f670aa213d046cf62936f32c to your computer and use it in GitHub Desktop.
Prevent commits on master branch (full relative path: .git/hooks/pre-commit)
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo 'No pushing to master'
exit 1 # commit will not execute
else
exit 0 # commit will execute
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment