Last active
December 28, 2015 00:19
-
-
Save tonicospinelli/7412381 to your computer and use it in GitHub Desktop.
Git Hook Pre Commit - deny commit in main branches
This file contains hidden or 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/sh | |
| #array with denied branches to commit | |
| uncommitBranches=( "develop" "master" "staging" "production" "live" ) | |
| #get the current branch | |
| branch_name="$(git rev-parse --abbrev-ref=strict HEAD 2>/dev/null)" | |
| for i in "${uncommitBranches[@]}" | |
| do | |
| if [ "$i" == "$branch_name" ] ; then | |
| echo " Oops... WAIT!" | |
| echo " You are trying to commit on the $branch_name branch." | |
| echo " Surely you don't mean that?" | |
| echo | |
| echo " If you really do, force the commit by adding --no-verify to the command. Not Recommended" | |
| echo | |
| exit 1 | |
| fi | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment