Last active
February 13, 2023 02:19
-
-
Save bpgould/e11356f42a2fb42ecda41540742e362c to your computer and use it in GitHub Desktop.
block commit to main using git hooks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
protected_branch='main' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [[ "$protected_branch" = "$current_branch" ]]; then | |
input='' | |
read -p "You're about to commit to master, is that what you intended? [y|n] " -n 1 -r </dev/tty | |
if [[ "$input" == [yY] || "$input" == [yY][eE][sS] ]]; then | |
exit 0 # commit will execute | |
fi | |
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
just add this to a file named .git/hooks/post-commit